![]() |
multi dimensional arrays in PHP - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: multi dimensional arrays in PHP (/showthread.php?tid=53242) |
multi dimensional arrays in PHP - El Forum - 07-16-2012 [eluser]obiron2[/eluser] Guys, I am struggling with the PHP logic to decode the following I have an array that looks like this: Code: $contacts = Array I want to pull the first key (phone, email) from the arrays to use as headings in the view. The view data will look like this Quote:<h1>Phone</h1> I can get the different records to group together by doing foreach($contacts as $group) and then foreach($group as $record) What I can't seem to get is the top level keys as values. The data comes from a single table of contacts, and is built by appending a results set for each contact type as an array to the contacts array. Is there a better approach for marshalling the data into an associative array Code for the contacts model and controller is below Code: model: multi dimensional arrays in PHP - El Forum - 07-16-2012 [eluser]CroNiX[/eluser] Code: foreach($contacts as $groupname => $groups) PS - For SEO, only 1 H1 tag allowed per page. |