richrock Posted September 9, 2009 Share Posted September 9, 2009 I have an array that has 'levels' - by which I mean: Item 1 - Item a Item b - Part 1 Part 2 Item c Item 2 - Item a Item b Item 3 - .... etc All I would like to do is return a list of top level elements in this array - so I would get: Item 1, Item 2, Item 3, without the sub parts like Item a, Part 1, etc. I can't seem to find a function on php.net that does this... Can it be done? Link to comment https://forums.phpfreaks.com/topic/173657-solved-recalling-toplevel-of-array/ Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 $array = array(array('item 1', array('part1', 'part2')), array('item 2'), array('item 3', array('sub1', array('subpart1')))); foreach ($array as $subArray) { echo $subArray[0]; } Link to comment https://forums.phpfreaks.com/topic/173657-solved-recalling-toplevel-of-array/#findComment-915392 Share on other sites More sharing options...
richrock Posted September 9, 2009 Author Share Posted September 9, 2009 Well, I'd assembled the array by a different method (db access) but the recall principle is the same - should have realised that Link to comment https://forums.phpfreaks.com/topic/173657-solved-recalling-toplevel-of-array/#findComment-915407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.