I have an nested array that's a mix of words and numbers. It looks like this conceptually. I need to process only numbered indexes such as 15
and 28
. I guess this means that I can't use a foreach
loop (or is there a way I could). How would you do this?
myarray = (
someindex = (
field1 =
field2 =
);
15 = (
field1 =
field2 =
);
28 = (
field1 =
field2 =
);
anothertext = (
field1 =
field2 =
);
);
foreach($myarr as $key => $item)
{
if(is_int($key))
{
// Do processing here
}
}
Yes, that will loop through every item in the array, so if you wanted to process the other items separately, you could just add in an else
block.
Edit: Changed is_numeric
to is_int
. See comments for explanation.
You can use foreach
foreach($myarray as $key=>$value)
{
if(is_int($key))
{
//process the entry as you want
}
}
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