0

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?

2
  • Looks more like an enumerated array to me, enumerated = with numbers as keys Commented Feb 27, 2015 at 14:51
  • Can be, sorry if I didn't specify it correctly Commented Feb 27, 2015 at 14:51

1 Answer 1

1
<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

Sign up to request clarification or add additional context in comments.

1 Comment

Damm I should make it by my self! Thank you @Ali, it was even easier then i think :) Going to mark it as correct when in 5 min (when i will be able to)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.