This may be a really dumb question but I’m just starting to learn the arrays function. I have this piece of code that works perfectly but only outputs the first value of the array which is [name]. I have a 2nd value in the array which is called [count] that I can’t seem to get to display. What is the correct key to use?
The array output is like this:
[215] => Array ( [name] => Category 1 [count] => 19 )
[263] => Array ( [name] => Category 2 [count] => 12 )
And this is the code:
while ($cat_details = $db->fetch_array($sql_select_categories))
{
$cat_array[$cat_details['category_id']]["name"]=$category_lang[$cat_details['category_id']];
$cat_array[$cat_details['category_id']]["count"]=$cat_details['items_counter'];
}
if(is_array($cat_array)){
asort($cat_array);
foreach($cat_array as $key => $value ){
$subcat_link = basename($_SERVER['PHP_SELF']) . '?parent_id=' . $key . $additional_vars;
$output .= '<tr> '.
' <td class="contentfont"> » <a href="' . $subcat_link . '">' . $category_lang[$key] . '</a></td> '.
'</tr> ';
}
}
I need to be able to display the $count somewhere in the HTML code of the foreach function. I tried everything from $cat_details[$count] to simply $count but it doesn’t seem to work.
If its inside the
foreachyou could use$value['count']to get the value you need