1

I am creating a new array ($Parts) from an existing array ($newarray), and reordering the array. However if the array key exists in the new array, I want to append to the 'location' and 'qty' arrays. Here is what the new array structure looks like:

     '4117-0171-249' => 
          'pri_id' => '859'
          'vendor' => 'R01298'
          'score' =>  '0.00'
          'location' => 
                 0 =>  '10103'
           'qty' => 
                 0 =>  '70' 

Here is my code I am using.

$Parts = array();
foreach($newarray AS $Ke => $Va) {
    if(array_key_exists($Va['part_number'], $Parts)){
         array_push($Parts[$location][],$Va['location']);
    } else {
    $Parts[$Va['part_number']] = array('pri_id' => $Va['pri_id'],
                                       'vendor' => $Va['vendor'],
                                       'score' => $Va['Score'],
                                          'location' => array($Va['location']),
                                          'qty' => array($Va['qty']),
                                        );
    }
 }
1
  • 1
    array_push($Parts[$location][],$Va['location']) makes no sense. You either do $Parts[$location][] = $Va['location'] or array_push($Parts[$location], $Va['location']), you can't mix the two syntaxes. Commented May 12, 2015 at 15:26

1 Answer 1

2

If anyone stumbles across this in the future, the answer was this:

$Parts[$Va['part_number']]['location'][] = $Va['location'];
Sign up to request clarification or add additional context in comments.

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.