1

I am generating a multidimensional array in the format:

Array ( 
  [0] => Array ( 
         [UAM 355T] => Array ([v1] => 1000 ) ) 
  [1] => Array ( 
         [UAM 355T] => Array ( [v2] => 2000 ) ) 
  [2] => Array ( 
         [UAP 702X] => Array ( [v3] => 3000 ) ) 
  [3] => Array ( 
          [UAP 702X] => Array ( [v4] => 4000 ) ) 
    ) 

Using the php script:

 $p = 0;
   while($p < $entries[$i])
       {
     $garage_record[] = array( $license[$i]=> array( $details[$p] =>    $cost[$p]));
    $p++;
    }


 print_r($garage_record);

Though I wanted it to be a two dimensional array where a license plate is linked to multiple entries in the form;

Array ( 
  [UAM 355T] => Array ([v1] => 1000 ), 
                      ([v2] => 2000)) 
  [UAP 702X] => Array(([v1] => 1000 ), 
                      ([v2] => 2000)) 
    ) 

Thanks

1
  • Have you tried it? What error did you get? Commented May 20, 2015 at 14:38

2 Answers 2

1

It's basic array manipulation, you can achieve what you want to do like that:

$p = 0;
while($p < $entries[$i])
{
   if (!isset($garage_record[$license[$i]]))
      $garage_record[$license[$i]] = array();

   $garage_record[$license[$i]][$details[$p]] = $cost[$p];
   $p++;
}

print_r($garage_record);
Sign up to request clarification or add additional context in comments.

Comments

0

You're probably looking for something like this:

foreach($records as $recordkey => $recordvalue) {
  foreach($recordkey as $subrecord) {
    $result[$recordkey][] = $subrecord;
  } 
}
print_r($result);

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.