$localKeys = array_column($arr1, 'product');
$remoteKeys = array_column($arr2, 'product');
$totalKeys = array_values(array_unique(array_merge($localKeys, $remoteKeys)));
$localLinks = array_combine(
$localKeys,
array_column($arr1, 'local_link')
);
$remoteLinks = array_combine(
$remoteKeys,
array_columns($arr2, 'remote_link')
);
$result = array_map(
fn($key) => [
'product' => $key,
'local_link' => $localLinks[$key] ?? null,
'remote_link' => $remoteLinks[$key] ?? null
]
);
print json_encode(['a', 'b']); // ["a","b"]
print json_encode([0 => 'a', 1 => 'b']); // ["a","b"]
print json_encode([1 => 'a', 2 => 'b']); // {"1":"a","2":"b"}
У вас массив заполняется по индексам $term->tid, которые не образуют классической последовательности, поэтому и представляются объектом.$vid = 'digest';
$termDataAll = array_map(
fn($term) => [
'tid' => $term->tid,
'name' => $term->name,
'weight' => $term->weight,
'childs' => array_map(
fn($child) => [
'tid' => $child->tid,
'name' => $child->name,
'weight' => $child->weight
],
\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid, $term->tid, 1)
)
],
\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid, 0, 1)
);
[
[
"tid": "11",
"name": "parent-1",
"weight": "7",
"childs": [
["tid": "14", "name": "child-1", "weight": "0"],
["tid": "19", "name": "child-2", "weight": "1"],
],
], [
"tid": "12",
"name": "parent-2",
"weight": "6",
"childs": [
["tid": "17", "name": "child-1", "weight": "0"],
["tid": "18", "name": "child-2", "weight": "1"]
]
]
]
$t = unserialize('a:2:{i:0;s:15:"_identity-admin";i:1;s:14:"[3,null,21600]";}');
var_dump($t);
// array(2) {
// [0] => string(15) "_identity-admin"
// [1] => string(14) "[3,null,21600]"
// }
sort(array &$array, int $flags = SORT_REGULAR): bool
function getMaxSkill(array $array, int $resource): ?A
{
return array_reduce(
$array,
fn($carry, $item) =>
$item->getCost() <= $resource
&& ($carry === null || $carry->getSkill() < $item->getSkill())
? $item
: $carry,
null
);
}
function genWords($alphabet, $length) {
$alph = mb_str_split($alphabet);
$maxChar = count($alph);
$idxs = array_fill(0, $length, 0);
while (true) {
yield implode('', array_map(fn($idx) => $alph[$idx], $idxs));
$pos = $length - 1;
while (true) {
$idxs[$pos] += 1;
if ($idxs[$pos] < $maxChar) {
break;
}
$idxs[$pos] = 0;
$pos -= 1;
if ($pos < 0) {
return;
}
}
}
}
foreach (genWords('АБВГДЕЁЖЗ', 5) as $word) {
print "{$word}\n";
}
function isSeq3(int $number) : bool
{
$prevDigit = 0;
$seqLen = 0;
while ($number > 0) {
$digit = $number % 10;
if ($digit === $prevDigit - 1) {
$seqLen += 1;
} else {
$seqLen = 1;
}
if ($seqLen === 3) {
return true;
}
$number = intdiv($number, 10);
$prevDigit = $digit;
}
return false;
}