i have this array here:
Array
(
[0] => Array
(
[presentation] => Präsentationen
)
[1] => Array
(
[news] => Aktuelle Meldungen
[devplan] => Förderprogramme
[salesdoc] => Vertriebsunterlagen
)
[2] => Array
(
[user/settings] => Mein Account
)
[3] => Array
(
)
[4] => Array
(
[orders] => Projekte
)
)
i want to unwrap the first depth of the array to get this:
Array
(
[presentation] => Präsentationen
[news] => Aktuelle Meldungen
[devplan] => Förderprogramme
[salesdoc] => Vertriebsunterlagen
[user/settings] => Mein Account
[orders] => Projekte
)
In order to remove an element from an array, we can use unset() function which removes the element from an array and then use array_values() function which indexes the array numerically automatically. Function Used: unset(): This function unsets a given variable.
The extract() function imports variables into the local symbol table from an array. This function uses array keys as variable names and values as variable values. For each element it will create a variable in the current symbol table. This function returns the number of variables extracted on success.
The array_shift() function removes the first element from an array, and returns the value of the removed element.
PHP | array_reduce() Function This inbuilt function of PHP is used to reduce the elements of an array into a single value that can be of float, integer or string value. The function uses a user-defined callback function to reduce the input array.
With PHP 5.3.0+:
array_reduce($array, 'array_merge', array());
I guess the simplest way is to use a foreach
loop:
$resultArray = array();
foreach ($myArray as $array)
foreach ($array as $key => $element)
$resultArray[$key] = $element;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With