edg322 Posted October 18, 2006 Share Posted October 18, 2006 Hello, I have a multi-dim array, $a which produces the following var_export($a):array ( 'some_ID' => 5, 'Create_Date' => '2004-02-20 15:18:13', 'some_Name' => 'foo', 'some_Description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.', 'Priority' => 1, 'some_URL' => 'http://www.fooname.com', 'Featured' => 1, 'Admin_ID' => 30, 'Status' => 'A', 'Last_Update' => '2004-08-31 11:29:27',)array ( 'some_ID' => 16, 'Create_Date' => '2000-06-14 10:10:36', 'some_Name' => 'bar', 'some_Description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.', 'Priority' => 2, 'some_URL' => 'http://www.bardomain.com', 'Featured' => 0, 'Admin_ID' => NULL, 'Status' => 'A', 'Last_Update' => '2003-08-18 15:43:22',)array ( 'some_ID' => 19, 'Create_Date' => '2006-06-19 11:15:59', 'some_Name' => '555', 'some_Description' => '555', 'Priority' => 555, 'some_URL' => '555', 'Featured' => 0, 'Admin_ID' => NULL, 'Status' => 'A', 'Last_Update' => '2006-10-17 10:28:32',)array ( 'some_ID' => 20, 'Create_Date' => '2006-06-20 11:36:01', 'some_Name' => 'anotherfoo', 'some_Description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.', 'Priority' => 7, 'some_URL' => 'http://www.anotherfoo.com/', 'Featured' => 0, 'Admin_ID' => NULL, 'Status' => 'A', 'Last_Update' => '2005-02-18 15:43:22',)My question is: How do I iterate through and only extract the value of 'some_ID' and place that into a table? Quote Link to comment https://forums.phpfreaks.com/topic/24334-multi-dimensional-arrays/ Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 You need a foreach loop...[code]<?phpforeach ($a as $key => $value){ // Do something with some_ID echo "{$a[$key]['some_ID']}<br>\n";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24334-multi-dimensional-arrays/#findComment-110689 Share on other sites More sharing options...
edg322 Posted October 18, 2006 Author Share Posted October 18, 2006 rockin, thx huggie Quote Link to comment https://forums.phpfreaks.com/topic/24334-multi-dimensional-arrays/#findComment-110694 Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 Try something like this for your table...[code]<?php// Open the tableecho "<table width=\"300\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">";// Loop through each instance in the arrayforeach ($a as $key => $value){ echo "<tr><td width=\"300\" align=\"center\">{$a[$key]['some_ID']}</td></tr>\n"; // Echo the table rows}// Close off the tableecho "</table>\n";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24334-multi-dimensional-arrays/#findComment-110702 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.