phorcon3 Posted December 1, 2007 Share Posted December 1, 2007 I really need some help with this, heres the code I got $Tshirts = array( '1' => array('Tshirt Name 1', 'S'), '2' => array('Tshirt Name 2', 'S'), '3' => array('Tshirt Name 3', 'M'), '4' => array('Tshirt Name 4', 'S'), '5' => array('Tshirt Name 5', 'S'), ); to display this code, I used the following $i = 0; foreach($Tshirts as $id_num => $name) { i++; echo '<a href="/view?id='.$id_num.'">'.$i.': '.$name[0].'</a>'; } and my question is how can I get the total number of Tshirts labelled Medium (M) or Small (S) in my arrays? Because I wanna create columns, such as: A F B G C H D I E J etc. ...but I need the total number of M's and S's so I know when to insert a break.. because right now its just a straight line going downward: A B C D E F G H I J It figured out how to get it to display like this: A B C D E F G H I J ..but that's not the way I want it I hope this makes sense lol.. I just can't figure out how to do it.. count($Tshirts) won't do much in this case Anway, I'd really appreciate it if someone could help me with this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/79635-multidimensional-arrays-count/ Share on other sites More sharing options...
marcus Posted December 1, 2007 Share Posted December 1, 2007 $x=1; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<tr><td>\n"; foreach($this AS $that){ echo $that . "<br>\n"; if($x == '5'){ echo "</td><td>\n"; $x=0; } $x++; } echo "</td></tr></table>\n"; something like that. Quote Link to comment https://forums.phpfreaks.com/topic/79635-multidimensional-arrays-count/#findComment-403299 Share on other sites More sharing options...
phorcon3 Posted December 1, 2007 Author Share Posted December 1, 2007 thanks for ya help. but thats actually not how I'd want it to be displayed I want there to be just 2 columns on the page. A L B M C N . . . . and I would need the total_number of all items lablled with M NEW_NUM = total_number / 2 if(is_int($i/NEW_NUM)){echo '</tr><tr>';} ...the link break Quote Link to comment https://forums.phpfreaks.com/topic/79635-multidimensional-arrays-count/#findComment-403307 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.