• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
displaying distributed php foreach lists in multidimensional array


it's well documented that in order to display a list from $data passed from the controller is pretty simple, I have successfully been doing it like this:

<ul>&lt;?php foreach ($sample_array as $array_item) { ?&gt;<li>&lt;?php echo $array_item; ?&gt; </li>&lt;?php } ?&gt;</ul>

As long as $sample_array is a one-dimensional array, the references work reliably.

But let's say the array fed into the view from $data in the controller is has two dimensions, associative or indexed, and we want to display the data in the same list item as a combined array. Hers some example data:

$data[$things] = array("thing1"=>"link for thing1","thing2"=>"link for thing2"..."thingX"=>"link for thingX"); // etc.

I'd like to produce the result of listing the items and item links in the same <LI> tags, obviously to make a hyperlink,

pseudocode: for each thing, echo <li><a src="$things[$thingX]">ThingX key</a></li></ul>

but how do I call the thingX key name? do i have to use a for() loop as an umbrella over the for each lists?

any suggestions for best practice with the view file? I'd rather not deal with combining the array in combining the array using array_combine() in the controller, although that might be one option. If there has been a discussion about this already in this forum, my search did not produce any results. Any comments welcome. Thanks!

Messages In This Thread
displaying distributed php foreach lists in multidimensional array - by El Forum - 10-18-2012, 07:20 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.