Answer the question
In order to leave comments, you need to log in
How to wrap array elements in an additional key (index)?
There is an array:
Array
(
[82] => Array
(
/*значения*/
)
[83] => Array
(
/*значения*/
)
[84] => Array
(
/*значения*/
)
)
Array
(
[0] => Array
(
[82] => Array
(
/*значения*/
)
)
[1] => Array
(
[83] => Array
(
/*значения*/
)
)
[2] => Array
(
[84] => Array
(
/*значения*/
)
)
)
Answer the question
In order to leave comments, you need to log in
<?php
$startArray = array(
50 => 'lorem',
70 => 'ipsum',
60 => 'dolor',
);
$endArray = array();
foreach($startArray as $key => $item) {
$endArray[] = array($key => $item);
}
print_r($endArray);
Loop through the array and create a new array with elements from the old one, as an option.
$map = function ($key, $value) { return [$key => $value]; };
$array = array_map($map, array_keys($array), array_values($array));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question