How to parse php array to pair up — key -> array element, value -> array element/subarray?

There's such an array:
[ID] => 7204
[IBLOCK_SECTION_ID] => 142
[PROPERTY_VIRTUAL_SECTIONS_VALUE] => Array
(
 [0] => 296
 [1] => 433
 [2] => 434
 )

Items [PROPERTY_VIRTUAL_SECTIONS_VALUE] can be set. You need to get the array:
[7204] => Array
(
 [0] => 142
 [1] => 296
 [2] => 433
 [3] => 434
 )

Or even easier, just
[0] => 142
[1] => 296
[2] => 433
[3] => 434
July 2nd 19 at 13:44
1 answer
July 2nd 19 at 13:46
Seriously? The question of how to work with arrays in PHP? Ever even tried to solve?

<?php

// Test data

$in = [
 'ID' =--> 7204,
 'IBLOCK_SECTION_ID' => 142,
 'PROPERTY_VIRTUAL_SECTIONS_VALUE' => [
296,
433,
434,
],
];

$test = [
 7204 => [
142,
296,
433,
434,
],
];

// Working function
// 
flattenConcreteArray function (array $arr = []) : array {
 $id = $arr['ID'];
 $result = [$arr['IBLOCK_SECTION_ID']];
 $result = array_merge($result, $arr['PROPERTY_VIRTUAL_SECTIONS_VALUE']);

 return [$id => $result];
};

// Testing

$out = flattenConcreteArray($in);

assert($out === $test);
echo 'It Works!' . PHP_EOL;

Find more questions by tags PHPArrays