Jump to content

Multidimensional Arrays Count


phorcon3

Recommended Posts

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! ;D

Link to comment
https://forums.phpfreaks.com/topic/79635-multidimensional-arrays-count/
Share on other sites

$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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.