I have a multidimensional array, I am interested in getting all the elements (one level deep) that don't have named keys.
i.e.
Array
{
['settings'] {...}
['something'] {...}
[0] {...} // I want this one
['something_else'] {...}
[1] {...} // And this one
}
Any ideas? Thanks for your help.
This is one way
foreach (array_keys($array) as $key) {
if(is_int($key)) {
//do something
}
}
EDIT
Depending on the size of your array it may be faster and more memory efficient to do this instead. It does however require that the keys are in order and none are missing.
for($i=0;isset($array[$i]);$i++){
//do something
}
$result = array();
foreach ($initial_array as $key => $value)
if ( ! is_string( $key ) )
$result[ $key ] = $value;
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