Page 1 of 1

building multi dimensional array

Posted: Thu Mar 13, 2008 6:47 am
by thatsme
Hello,

I have a swf which generates graph. It needs the data in an array format.

Code: Select all

 
<?php
$line=array(1,2,3,4).  //Its working fine.
$line2=array(3,2,5,6).
?> 
 
I am trying to build arrays for each member scores ($final_member_score) like above.

In my application, there will be many members. Each member will get a set of scores on some calculation. Please see below, $line is a line drawn by plotting points 1,2,3,4

Code: Select all

 
<?php 
$line=array(1,2,3,4).
 
$member_ids = array(1,2,3,4);
$test_ids = array(1,2);
?> 
 
 
// this is the code i wrote.  Can someone help me in building array of scores for each members 
 
<?php 
for($member_count=0; $member_count<count($member_ids); $member_count++)
{
   for($test_count=0; $test_count<count($test_ids); $test_count++)
   {
 
     $as=GetApplicantScore($member_ids[$member_count], $test_ids[$test_count]);
 
     $hs=GetAllotedScore(1, $test_ids[$test_count]);
     $final_member_score = $as-$hs;
   //$final_member_score should be in array format. 
  // $final_member_score[] = $as-$hs // now the $final_member_score will contain all members score.  I should be able to iterate scores, tests for each members seperately.  I hope my explaination clear.
}
}
?>
 
Thanks

Re: building multi dimensional array

Posted: Thu Mar 13, 2008 2:59 pm
by Christopher
Did you try $final_member_score[] = $as-$hs; ? If so how was it wrong?

Re: building multi dimensional array

Posted: Fri Mar 14, 2008 12:51 am
by thatsme
Did you try $final_member_score[] = $as-$hs; is working. Its not giving individual members values. I am getting values of all members.

what i need is arrays like,

Code: Select all

 
<?php
$member1=array(1,2,3,4,5);
$member2=array(5,2,4,4,5);
$member3=array(5,2,4,3,2);
$member4=array(1,2,4,3,2);
?>
 
I should get arrays like above dynamically.

Re: building multi dimensional array

Posted: Fri Mar 14, 2008 1:32 am
by Christopher
Then do:

Code: Select all

$final_member_score[$member_count][] = $as-$hs;

Re: building multi dimensional array

Posted: Mon Mar 17, 2008 9:18 am
by thatsme
$final_member_score[$member_count][] = $as-$hs;
Thanks. That's what i was looking for. If i want to add first_name and last_name to the array, how should i do it.