Смысл двух разных вариантов для операторов "and" и "or" в том, что они работают с различными приоритетами (смотрите таблицу Приоритет выполнения операторов).
&&
- 15 строка, =
- 19 строка, and
- 23 строка.$bool = true and false;
=> ($bool = true) and false;
$bool = true && false;
=> $bool = (true && false);
$grouped = [];
foreach ($arr as $n) {
$grouped[$n['category_id']][] = $n['text'];
}
foreach ($grouped as $key => $values) {
echo "
<fieldset>
<legend>$key</legend>".
implode('', array_map(fn($n) => "<div>$n</div>", $values))."
</fieldset>";
}
.clients__box {
outline: 1px solid red;
margin: 0 40px;
margin-bottom: 20px;
width: calc(100% / 3 - 80px) !important;
}
{9}
пусть будет {4,9}
, например. Или {6,9}
. Или... Сами решайте, сколько их должно быть, вам виднее.a-z
, а a-f
. $data = ['row1', 'row2', 'row3', 'row4', 'row5'];
$countToDelete = 3;
$i = 0;
foreach ($data as $index => $value) {
unset($data[$index]);
if ($i >= $countToDelete - 1) {
break;
}
$i++;
}
var_dump($data);
/*
array(2) {
[3]=>
string(4) "row4"
[4]=>
string(4) "row5"
}
*/
$data = ['row1', 'row2', 'row3', 'row4', 'row5'];
$countToDelete = 3;
$filtered = array_filter($data, function ($value) use (&$countToDelete) {
return $countToDelete-- <= 0;
});
var_dump($filtered);
/*
array(2) {
[3]=>
string(4) "row4"
[4]=>
string(4) "row5"
}
*/
<?php
$string = 'This is my habr';
$pattern = '/(\w+ \w+)$/i';
$replacement = '<a href="habr.com">${1}<a>';
echo preg_replace($pattern, $replacement, $string);
<?php
header( 'Content-type: text/html; charset=utf-8' );
echo 'Begin ...<br />';
for( $i = 0 ; $i < 10 ; $i++ )
{
echo $i . '<br />';
flush();
ob_flush();
sleep(1);
}
echo 'End ...<br />';
?>
<?php
$data = [
[
'id' => 1,
'parent_id' => 100,
'name' => 'Стулья'
], [
'id' => 2,
'parent_id' => 100,
'name' => 'Столы'
], [
'id' => 5,
'parent_id' => 1,
'name' => 'Стул Сакура',
'price' => 5691,
'img' => 'lorempixel.com/900/900/?q=5',
'props' => []
], [
'id' => 9,
'parent_id' => 2,
'name' => 'Стол Византия',
'price' => 5268,
'img' => 'lorempixel.com/900/900/?q=9',
'props' => []
]
];
function build_tree($data, $id) {
$result = [];
foreach ($data as $el) {
if ($el['parent_id'] == $id) {
$newEl = $el;
$childs = build_tree($data, $el['id']);
if (count($childs) !== 0) {
$newEl['childs'] = $childs;
}
$result[] = $newEl;
}
}
return $result;
}
$tree = build_tree($data, 100);
print_r($tree);
/*
Array (
[0] => Array (
[id] => 1
[parent_id] => 100
[name] => Стулья
[childs] => Array (
[0] => Array (
[id] => 5
[parent_id] => 1
[name] => Стул Сакура
[price] => 5691
[img] => lorempixel.com/900/900/?q=5
[props] => Array ()
)
)
)
[1] => Array (
[id] => 2
[parent_id] => 100
[name] => Столы
[childs] => Array (
[0] => Array (
[id] => 9
[parent_id] => 2
[name] => Стол Византия
[price] => 5268
[img] => lorempixel.com/900/900/?q=9
[props] => Array ()
)
)
)
)
*/