if (empty($_POST) && $_GET) {
foreach($_GET as $k=>$v) {
$_POST[$k] = $v;
}
}$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.site.com/vote.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_GET));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
var_dump($server_output)http://site.com/vote-redirect.php<form action="http://www.site.com/vote.php" method="POST" id="form">
<input type="hidden" name="vote[1]" value="<?=intval($_GET['vote_1']??1)?>">
<input type="hidden" name="vote[2]" value="<?=intval($_GET['vote_2']??0)?>">
</form>
<script>
document.getElementById('form').submit();
</script>http://site.com/vote-redirect.php?vote_1=1&vote_2=0 $sql = mysqli_query($link, "SELECT * FROM reg WHERE name='$name' LIMIT 1");
if (!mysqli_num_rows($sql)) { // логин не найден
echo 'неверный логин и пароль';
} else { // логин найден
$result = mysqli_fetch_array($sql)
if($result['password'] == $password){ // пароль верный
echo 'логин и пароль верные';
}else{ // пароль не верный
echo 'неверный логин и пароль';
}
} $items = SELECT * FROM table WHERE parent_id=0
foreach($items as $item)
{
echo $item->name
$subitems = SELECT * FROM table WHERE parent_id={$item->id}
foreach ($subitems as $subitem) {
echo $subitem->name
}
}$items = SELECT * FROM table
$menu = [];
foreach($items as $item) {
if ($item->parent_id == 0) {
$menu[$item->id]['parent'] = $item;
} else {
$menu[$item->parent_id]['items'][] = $item;
}
}
foreach ($menu as $item) {
echo $item['parent']->name;
if (!empty($item['items'])) {
foreach ($item['items'] as $subitem) {
echo $subitem->name;
}
}
}$printer = function printNode($items) {
foreach($items as $item) {
echo $item->name
$subitems = SELECT * FROM table WHERE parent_id={$item->id}
if ($subitems) {
printNode($subitems);
}
}
}
$items = SELECT * FROM table WHERE parent_id=0
printNode($items) RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?route=$1 [QSA,L]try {
// берем переданный роут
$route = trim($_REQUEST['route']??'index');
// проверяем, если в конце слеш, то это index роут
if (substr($route,'-1') == '/') $route.='index';
// минимальная защита от инклуда неожидаемых файлов
// ограничиваем имена до символов a-b, 0-9, тире, нижнее подчеркивание и слеш
if (!preg_match('~^[-a-z0-9/_]+$~i', $route)) throw new Exception('Not allowed route');
// генерим путь к файлу
$filePath = dirname(__FILE__).'/pages/'.$route.'.php';
// если не существует выкидываем ошибку
if (!file_exists($filePath)) throw new Exception('Route not found');
// если существует, инклудим файл
include $filePath;
} catch (Throwable $ex) {
// в случае любых ошибок, показываем 404
// тут обычно делают разные типы эксепшенов и разделяют 400 и 500 ошибки
include dirname(__FILE__).'/pages/404.php';
}$type = $_POST['type'];
var_dump($type);$question = 'n/a';
...
If($type == 'surname'){
echo "1";
$question = $_POST['surname_3'];$type = $_POST['type'];
switch($type) {
default: // если тип не опознан сгенерировать ошибку
throw new Exception('Undefined type: '.$type);
break;
case 'surname':
$question = $_POST['surname_3'];
break;
case 'id_publick':
$question = $_POST['id_3'];
break;
case 'phone_num':
$question = $_POST['phone_num_3'];
break;
} <a onclick="if (!cofirm('Точно удалить?')) return false" href="#">удалить</a>Вроде можно с помощью JS, но я в нём не особо разбираюсь пока что
foreach($newItems as $newItem) {
foreach($oldItems as $oldItem) {
}
}$existedItems = [...]
foreach($newItems as $newItem) {
$oldItems = $existedItems;
foreach($oldItems as $k=>$oldItem) {
unset($existedItems[$k]);
}
}$newItems = [];
foreach($newItemsXml as $newItemXml) {
$hash = $newItemXml->storeId.'::'.$newItemXml->sku; // генерим хеш
$newItems[$hash] = $newItemXml;
}
...
// то же самое для $oldItems
...
foreach ($newItems as $hash=>$newItem) {
$oldItem = $oldItems[$hash]; // максимально быстрая выборка
...
}var_dump ($zaif->fetch_ticker ('BTC/JPY'));array(20) {
["symbol"]=>
string(7) "XMR/ETH"
["timestamp"]=>$data = $zaif->fetch_ticker ('BTC/JPY')var_dump($zaif->fetch_ticker ('BTC/JPY'))echo $data ["symbol"]; // выведет XMR/ETH <?php
function tpl_tpluralForm($n, $form1, $form2, $form3)
{
$n = abs($n) % 100;
$n1 = $n % 10;
if ($n > 10 && $n < 20) {
return $form3;
}
if ($n1 > 1 && $n1 < 5) {
return $form2;
}
if ($n1 == 1) {
return $form1;
}
return $form3;
}
$seconds = 2*24*60*60 + 8*60*60;
$days = floor( $seconds / (24*60*60) );
$hours = $seconds < 24*60*60
? floor( $seconds / (60*60) )
: floor( ($seconds % (24*60*60)) / (60*60) )
;
echo $days.' '.tpl_tpluralForm($days, 'день', 'дня', 'дней')
.' '.$hours.' '.tpl_tpluralForm($hours, 'час', 'часа', 'часов');$products = $this->getProductList();
if ($products) {$products = $this->getProductList();
if (is_iterable($products)) {$products = $this->getProductList();
if (is_countable($products)) {$stmt = mysqli_prepare($link, "INSERT IGNORE INTO Users (a1, a2, a3, s1, s2) VALUES (?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssss', $a1, $a2, $a3, $s1, $s2);
foreach($json['object'] as $item) {
$a1 = $item['a1'];
$a2 = $item['a2'];
$a3 = $item['a3'];
$s1 = $item['s1'];
$s2 = $item['s2'];
mysqli_stmt_execute($stmt);
}
mysqli_stmt_close($stmt);
mysqli_close($link); <?php
$go = ['test1','test2','test3'];
print_r(array_reverse($go, true));Array ( [2] => test3 [1] => test2 [0] => test1 )<?php
$go = ['test1','test2','test3'];
for ($i=count($go)-1; $i>=0; $i--) {
echo $i.' => '.$go[$i].'<br>';
}2 => test3
1 => test2
0 => test1 <?php
$arr = [
8=>array (
'id' => '9',
'master_theme' => 'Безопасность',
'theme' => 'Светофоры',
),
9 =>
array (
'id' => '10',
'master_theme' => 'Безопасность',
'theme' => 'Экологическая полиция',
),
10 =>
array (
'id' => '11',
'master_theme' => 'Благоустройство',
'theme' => 'Благоустройство ВДНХ',
),
11 =>
array (
'id' => '12',
'master_theme' => 'Благоустройство',
'theme' => 'Благоустройство водоёмов',
),
];
$res = [];
foreach($arr as $item) $res[$item['master_theme']][] = $item['theme'];
echo '<pre>';
print_r($res);
echo '</pre>';Array
(
[Безопасность] => Array
(
[0] => Светофоры
[1] => Экологическая полиция
)
[Благоустройство] => Array
(
[0] => Благоустройство ВДНХ
[1] => Благоустройство водоёмов
)
)