Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi Larry,

 

i'm quite new to the forum, just have a quick question from chapter one from the pursue section, basically how would I display each element in the multidimentional array? without using print_r. Would I use a foreach loop to loop through element or within a function use a array_key_exist to test if key exist, then if true return that data from array please let me know.

 

regards,

fred

Link to comment
Share on other sites

Sorry about the delay! Behind schedule keeping up with the forums! It sounds like you have the basic grasp of looping through a multidimensional array. If you know the depths of the array, you can use X number of nested foreach loops. Otherwise you'll need to use a recursive function or http://php.net/array_walk_recursive, which is a shortcut there. 

 

The PHP Advanced book does have a recursive example of example this. 

Link to comment
Share on other sites

  • 2 months later...

Sorry about the delay! Behind schedule keeping up with the forums! It sounds like you have the basic grasp of looping through a multidimensional array. If you know the depths of the array, you can use X number of nested foreach loops. Otherwise you'll need to use a recursive function or http://php.net/array_walk_recursive, which is a shortcut there. 

 

The PHP Advanced book does have a recursive example of example this. 

Hi Larry,

 

been away for summer, just a quick one you know the 'array_walk_recursive' function how would I capture the Keys which are also arrays in the the multi-dimensional array because I used the array_map and it worked with the call back function but the key which are arrays didnt display for example could I say in user defined function '$key1 => $key2' => $value' I know this isnt quite right but i'm a bit unsure, please let me know.

 

bless,

 

fred.

Link to comment
Share on other sites

  • 1 month later...
 Share

×
×
  • Create New...