ds111 Posted December 22, 2009 Share Posted December 22, 2009 Hi! I have an array like this: [test1] => [test2] => [test3] => Array ( [archives] => Array ( [file] => application/hooks/archives.php [function] => archives ) ) How can I make a foreach loop so that it takes the "archives" text out of test 'test3' index? Afterwards, I then need to take the "file" and "function" out, also in the foreach loop. I also need an "if" statement, to check if there is anything in the 'test1' index as well. All 3 indexes will be called, and I need to loop through each of them. If there is anything there, I need to loop through those, and include the "file" one. Link to comment https://forums.phpfreaks.com/topic/185978-foreach-loop-question/ Share on other sites More sharing options...
ds111 Posted December 22, 2009 Author Share Posted December 22, 2009 Sorry, (can't edit post). If it's in a for loop, that's even better Link to comment https://forums.phpfreaks.com/topic/185978-foreach-loop-question/#findComment-982071 Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 You just need a check to see if the inner value is an array. eg; foreach ($arr as $k => $v) { if (is_array($v)) { foreach ($b as $key => $val) { // } } } If your going to go any deeper than that you might want to look into recursion. Link to comment https://forums.phpfreaks.com/topic/185978-foreach-loop-question/#findComment-982076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.