I have an PHP array looking like this:
$array[\'my_data\'][\'value\'] = \'some value\';
$array[\'my_own_data\'][\'value\'] = \'another value\';
$array[\'diff
The problem is that the number of first level keys are unknown. It could be 150 items, I don't know.
That's a problem easy to solve.
If you want to know the number of keys of the first level:
$numberOfKeysOfTheFirstLevel = count($array);
There you know the number now. If you need actually their names, you can do so as well:
$keyNamesOfTheFirstLevel = array_keys($array);
So then you continued in your question:
This would not work for me because of the unknown number of keys:
array_merge($array['my_data'], $array['my_own_data'], $array['different_data']);
The good news is, you don't need to know the number of keys to perform your array_merge
operation:
call_user_func_array('array_merge', $array);
So regarding to what you wrote about in your question, this should answer it. However the result might not be what you expected. See the other answers as well please and please ask.