Namit
Namit

Reputation: 1322

storing multiple values in multi dimensional array

I have a two dimensional array:

$scores = array(array(),array());

I then have a for loop which is runs data from another array:

for($i = 0; $i < sizeof($teams); $i++) {
    $current_team = $teams[$i];
    // some calculations and value stored in a variable named sum.
    $scores($current_team, $sum); // this certainly is wrong.
}

I need to store the $current team in array one and the $sum in array two within the $score array. I tried to find information about storing multiple values in an array, but could find it. Any help will be appreciated.

Upvotes: 0

Views: 159

Answers (3)

PFY
PFY

Reputation: 336

Are you looking for something like
$scores[] = array('team_name'=>$current_team,'sum'=>$sum);

or something more like
$scores[$current_team] = $sum;

Upvotes: 0

Ingmar Boddington
Ingmar Boddington

Reputation: 3500

$scores['0'][] = $current_team;
$scores['1'][] = $sum;

Upvotes: 0

Ry-
Ry-

Reputation: 224886

So you want column 1 to be $current_team and column 2 to be $sum? Just create a new array on the spot, and use the $array[] syntax to add an item:

$scores[] = array($current_team, $sum);

If you wanted them stored inside the arrays as "rows", however, you would use:

$scores[0][] = $current_team;
$scores[1][] = $sum;

Upvotes: 1

Related Questions