Reputation: 5762
I have array which looks like this:
"$companies" => array (6)
0 => 44.0
1 => 1399.0
2 => 0.0
3 => 2.0
4 => 750.0
12 => 0.0
where first number represent company ID and second number represent SUM() of one column from the table.
I belieave you skilled guys meet with something like this milions times (not like me.) What i need is to create a table where each line is 1 company and in each line there are 2 where first gonna be ID and second gonna be value
<tr n:foreach="$companies as $company">
<td>{$company}</td>
<td class="center">{$company[1]}</td>
</tr>
Problem is that, I never know how many companies there gonna be, and what ID they will have so i can't use something like echo $companies[0];
How you suggest to add this to table?
Upvotes: 0
Views: 33
Reputation: 3461
<tr n:foreach="$companies as $company_id => $sum">
<td>{$company_id}</td>
<td class="center">{$sum}</td>
</tr>
$company_id
would hold the key
$sum
would hold the value
Upvotes: 1