tammclaughlin Posted November 27, 2009 Share Posted November 27, 2009 Hi, I have been going round in circles reading the docs on the different ways to use 2D arrays but getting stuck at the best method of achieving what I want. This is what I want to do: Display a list of user details in a random order in multiple colums. I looked at retrieving the details from a csv file which was ok, but could not find a way to convert the info into a 2d array so I created a static array as follows: $members=array( "name1" => array ("Mr", "Tam", "Meechan","0123 5454","myemail@me.com","url1,"url2"), "name2" => array ("Mr", "Joe", "Bloggs","0123 112233","hisemail@me.com","url1,"url2"), "name3" => array ("Mr", "Bo", "Frank","0123 9900","noemail@me.com","url1,"url2"), ); my test code to print the details is: count=count($members); foreach ($members as $key => $val) { for($i=0;$i<$count;$i++) { print "<tr>"; print "<td>$val[$i]</td>"; } print "</tr>"; } I know the output is not yet formatted e.g. I would want the first 3 values of the inner array to be displayed together on the same table row. However, I want to display as follows: $val[$i] $val+1 [$i] but don't know how to access the next element in the outer array. Any ideas? Also, if I want to shuffle the array keys name1, name2 etc, is it better to use integers for the keys rather than a string? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/183104-getting-next-element-1-in-a-2d-array/ Share on other sites More sharing options...
Zane Posted November 27, 2009 Share Posted November 27, 2009 $val[$i+1] Quote Link to comment https://forums.phpfreaks.com/topic/183104-getting-next-element-1-in-a-2d-array/#findComment-966347 Share on other sites More sharing options...
tammclaughlin Posted November 27, 2009 Author Share Posted November 27, 2009 Thanks for the reply. However, I don't think I explained myself properly. $val[$i+1] would let me access the next element in the array for details for name1 whereas I want to access the same details for name2 e.g. currently I have: name1 mr tam meechan 01....... name2 but want: name1 name 2 name3 mr mr mr tam joe bo meechan bloggs frank Quote Link to comment https://forums.phpfreaks.com/topic/183104-getting-next-element-1-in-a-2d-array/#findComment-966348 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.