function getRootItem($id, $array) {
foreach ($array as $item) {
if ($item['id'] === $id) {
$parent = $item['parent'];
return $parent === 0 ? $item : getRootItem($parent, $array);
}
}
return null;
}
function walk($data, $key, &$result) {
foreach ($data as $k => $v) {
if (!array_key_exists($k, $result)) {
$result[$k] = [];
}
if (!is_array($v) || array_keys($v) === range(0, count($v) - 1)) {
$result[$k][$key] = $v;
} else {
walk($v, $key, $result[$k]);
}
}
}
function merge(...$arrays) {
$result = [];
foreach ($arrays as $arr) {
$key = array_keys($arr)[0];
walk($arr[$key], $key, $result);
}
return $result;
}
$result = merge($array1, $array2);
$arr = [
"raz" => [
"qqq" => [ "6" ],
"www" => [ 0 ]
],
"dva" => [
"qqq" => [ 0 ],
"www" => [ 0 ]
]
];
function printArr($arr, $path = '') {
foreach ($arr as $key => $val) {
if (is_array($val)) {
printArr($val, $path."[$key]");
} else {
echo $path."[$val]<br>";
}
}
}
printArr($arr);
Я тут начинаю изучать php с фреймворка yii2
$str = "философски нагруженная";
preg_match("/.{50}$str.{50}/u", $text, $match);
preg_match_all('/\-?\d+/', $str, $matches);
$numstr = implode(' ', $matches[0]);
$arr = array_chunk(range(1, 12), 3);
foreach ($arr as $chunk) {
echo "<div>";
foreach ($chunk as $value) {
echo "<div>$value</div>";
}
echo "</div>";
}
foreach ($obj_guild['members'] as $m) {
$username = $m['user']['username'];
echo "$username - будет расстрелян<br>";
}
array_map(function($n) {
return [
'date' => $n[0],
'sum' => $n[1]
];
}, array_chunk($arr, 2))