$doc = new DOMDocument();
$doc->loadHTML($html);
$a = $doc->getElementsByTagName('a');
$result = array_map([ $doc, 'saveHTML' ], iterator_to_array($a));
$result = preg_split('/(?<=\/a>)(?=<a)/', $html);
// или
preg_match_all('/<a .*?>.*?<\/a>/', $html, $matches);
$result = $matches[0];
$grouped = array_map(function($n) {
for ($i = 1; $i < count($n); $i++) {
$min = min($n[$i]);
$max = max($n[$i]);
$n[$i] = ($min === $max) ? $min : "$min-$max";
}
return $n;
}, array_values(array_reduce($arr, function($acc, $n) {
$acc[$n[0]] ??= [ $n[0] ];
for ($i = 1; $i < count($n); $i++) {
$acc[$n[0]][$i][] = $n[$i];
}
return $acc;
}, [])));
$result = array_sum(array_filter(
array_count_values($all_items),
fn($n) => in_array($n, $filters),
ARRAY_FILTER_USE_KEY
));
$result = count(array_intersect($all_items, $filters));
$sum = array_sum(array_column($arr, 'price'));
foreach ($arr as &$n) {
$n['weight'] = number_format($n['price'] / $sum * 100, 2).'%';
}
public function expose() {
return array_map(fn($n) => $n instanceof Text ? $n->expose() : $n, get_object_vars($this));
}
usort($lots, function($a, $b) use($currencyLists) {
$ia = array_search($a['currency'], $currencyLists);
$ib = array_search($b['currency'], $currencyLists);
$t = $ia - $ib;
return $t ? $t : ($a['lotSize'] - $b['lotSize']);
});
Удалили под индексом 2 <...> элемента под индексом 2 нет
function merge($idKey, $mergeKeys, ...$data) {
$merged = [];
foreach (array_merge(...$data) as $item) {
$id = $item[$idKey];
if (!array_key_exists($id, $merged)) {
$merged[$id] = [
'unique' => true,
'item' => $item,
];
} else {
if ($merged[$id]['unique']) {
$merged[$id]['unique'] = false;
foreach ($mergeKeys as $k) {
$merged[$id]['item'][$k] = [ $merged[$id]['item'][$k] ];
}
}
foreach ($mergeKeys as $k) {
$merged[$id]['item'][$k][] = $item[$k];
}
}
}
return array_column($merged, 'item');
}
$merged = merge('code', [ 'quantity', 'city' ], $arr1, $arr2);
$values = array_combine(
array_column($example2, 'SECTION_ID'),
array_column($example2, 'VALUE')
);
$example3 = array_map(function($n) use($values) {
$n['VALUE'] = $values[$n['SECTION_ID']];
return $n;
}, $example1);
function generator($str, $params) {
$result = [];
if (count($params)) {
$key = key($params);
$values = is_array($params[$key]) ? $params[$key] : [ $params[$key] ];
unset($params[$key]);
foreach ($values as $val) {
array_push($result, ...generator(str_replace("{{$key}}", $val, $str), $params));
}
} else {
$result[] = $str;
}
return $result;
}