0

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.

3 Answers 3

1

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;
Sign up to request clarification or add additional context in comments.

2 Comments

If i use this method, will i be able to read it by this: $scores[0][1].
@Namit: Yes. The first one is what you need, I think.
0
$scores['0'][] = $current_team;
$scores['1'][] = $sum;

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.