views:

41

answers:

2

ok so i am creating a multidementional array and this line only allows one element into it. How do i check to see if

$related[$row_r['Category_name']][$row_r['name']]

is greater then 0 and if so dont overwrite the value and just append onto it

while($row_r = mysql_fetch_assoc($result)){
  $related[$row_r['Category_name']][$row_r['name']] = $row_r; //this line
+3  A: 

Perhaps you're looking for this?

while($row_r = mysql_fetch_assoc($result)){
    $related[$row_r['Category_name']][$row_r['name']][] = $row_r;
}
WoLpH
+1  A: 
$value=$related[$row_r['Category_name']][$row_r['name']];
if(is_int($value) && $value>0) {//if current value is a >0 integer
  $related[$row_r['Category_name']][$row_r['name']] = array($value, $new_value);//we combine the new value too, together with the previous one, into an array
} elseif(is_array($value)) {//if  it was already an array, we append the new element
  $related[$row_r['Category_name']][$row_r['name']][] = $new_value;
} else {//other wise (a 0 integer), we would assign the value.
  $related[$row_r['Category_name']][$row_r['name']] = $new_value;
}
aularon