$array = [
'03.2001' => [],
'01.2000' => [],
'01.2005' => [],
'05.2020' => [],
'01.2020' => [],
'30.1998' => [],
'03.2020' => [],
'09.2020' => [],
'04.1998' => [],
'11.2005' => [],
];
uksort($array, function(string $a, string $b): int {
return date_create_from_format('m.Y', $a) <=> date_create_from_format('m.Y', $b);
});
function get_footer()
{
global $link;
$sql = "SELECT * FROM footer WHERE id in (1, 2, 3)";
$result = mysqli_query($link, $sql);
$posts = array();
while ($row = $result->fetch_assoc()) {
$postId = $row['id'];
$posts[$postId] = $row;
}
return $posts;
}
<div class="col-xl-6">
<img src="img/logo.svg" alt="logo" class="logo_footer">
<p><?php echo $posts[1]['description'] ?></p>
</div>
<div class="col-xl-3">
<h5><?php echo $posts[2]['title'] ?></h5>
<p><?php echo $posts[2]['description'] ?></p>
</div>
<div class="col-xl-3">
<h5><?php echo $posts[3]['title'] ?></h5>
<p><?php echo $post[3]['description'] ?></p>
</div>
$json = '[{"id":"352","name":"Сырники из тофу","category":"Завтрак","time":"10:00"},{"id":"355","name":"Овсяная каша","category":"Завтрак","time":"10:00"},{"id":"350","name":"Кефир","category":"Завтрак","time":"10:00"},{"id":"356","name":"Морковный фреш","category":"Завтрак","time":"10:00"},{"id":"359","name":"Салат из помидоров","category":"Обед","time":"14:00"},{"id":"360","name":"Куриный суп с лапшой","category":"Обед","time":"14:00"},{"id":"363","name":"Котлеты из курицы с салатом","category":"Обед","time":"14:00"},{"id":"365","name":"Салат из Десяти фруктов","category":"Обед","time":"14:00"},{"id":"366","name":"Морс Лесные ягоды","category":"Обед","time":"14:00"},{"id":"358","name":"Салат с индейкой","category":"Ужин","time":"20:00"},{"id":"362","name":"Куриная грудка с салатом","category":"Ужин","time":"20:00"},{"id":"364","name":"Тонкий яблочный пирог","category":"Ужин","time":"20:00"},{"id":"367","name":"Морс клюквенный","category":"Ужин","time":"20:00"}]';
$jsonAsArray = json_decode($json, true);
$breakfast = [];
$lunch = [];
$dinner = [];
foreach ($jsonAsArray as $item) {
switch ($item['category']) {
case 'Завтрак':
$breakfast[] = $item;
break;
case 'Обед':
$lunch[] = $item;
break;
case 'Ужин':
$dinner[] = $item;
break;
}
}
print_r($breakfast);
print_r($lunch);
print_r($dinner);
function handler(array $input): array
{
$output = $input;
$idsForDelete = [];
foreach ($input as $i => $item) {
$code = $item['CODE'];
$number = $item['NUMBER'];
if ($code !== 300) {
continue;
}
$key = $number . '-' . $code;
if (isset($idsForDelete[$key])) {
$idsForDelete[$key][] = $i;
} else {
$idsForDelete[$key] = [];
}
}
foreach ($idsForDelete as $ids) {
foreach ($ids as $i => $id) {
unset($output[$id]);
}
}
$arrayWith200 = [];
$arrayWith300 = [];
foreach ($output as $i => $item) {
$code = $item['CODE'];
$number = $item['NUMBER'];
if ($code === 200) {
$arrayWith200[$i] = $number;
}
if ($code === 300) {
$arrayWith300[$i] = $number;
}
}
foreach ($arrayWith300 as $i => $number) {
$key = array_search($number, $arrayWith200);
if ($key === false) {
continue;
}
unset($output[$i]);
unset($output[$key]);
}
return $output;
}
print_r(handler($arr));
Array
(
[6] => Array
(
[ID] => 7
[CODE] => 300
[NUMBER] => 10003
[DATE] => 2020-03-01T10:00:00
)
)
$this->addPost($postinfo, $url, $post)
$image = new Imagick();
$image->newImage(800, 75, new ImagickPixel('transparent'));
$draw = new ImagickDraw();
$draw->setFillColor('#000'); // цвет текста
$draw->setFont('path/to/font/Atial.ttf'); // путь до файла со шрифтом
$draw->setFontSize(30); // размер шрифта
$image->annotateImage($draw, 0, 0, 0, 'Текст Текст');
$image->setImageFormat('png');
PHP поддерживает списки аргументов переменной длины для функций, определяемых пользователем. Для версий PHP 5.6 и выше это делается добавлением многоточия (...). Для версий 5.5 и старше используются функции func_num_args(), func_get_arg() и func_get_args().
$array = array(
0 => array('id'=> 2, 'title' => 'text', 'category' => 0),
1 => array('id'=> 4, 'title' => 'text', 'category' => 1),
2 => array('id'=> 5, 'title' => 'text', 'category' => 0),
);
function catSort($a, $b)
{
if ($a['category'] == $b['category']) {
return 0;
}
return ($a['category'] < $b['category']) ? -1 : 1;
}
usort($array, "catSort");
print_r($array);
Array
(
[0] => Array
(
[id] => 2
[title] => text
[category] => 0
)
[1] => Array
(
[id] => 5
[title] => text
[category] => 0
)
[2] => Array
(
[id] => 4
[title] => text
[category] => 1
)
)
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
Request URL:http://chehl.ru/page/2/
Request Method:GET
Status Code:404 Not Found