building multi dimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thatsme
Forum Commoner
Posts: 87
Joined: Sat Apr 07, 2007 2:18 am

building multi dimensional array

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: building multi dimensional array

Post by Christopher »

Did you try $final_member_score[] = $as-$hs; ? If so how was it wrong?
(#10850)
thatsme
Forum Commoner
Posts: 87
Joined: Sat Apr 07, 2007 2:18 am

Re: building multi dimensional array

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: building multi dimensional array

Post by Christopher »

Then do:

Code: Select all

$final_member_score[$member_count][] = $as-$hs;
(#10850)
thatsme
Forum Commoner
Posts: 87
Joined: Sat Apr 07, 2007 2:18 am

Re: building multi dimensional array

Post 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.
Post Reply