php - Append array with variable -


so doing creating function pass in array append array. here "trying" do:

global $shirts; global $prices;  $shirts = array(         'option1' => array(),         'option2' => array(),     );  $prices = array(         'product1' => array(                         'bronze' => 1,                          'silver' => 2,                          'gold' => 3,                        ),         'product2' => array(                         'bronze' => 4,                          'silver' => 5,                          'gold' => 6,                        ),       );   function shirts($shirts_model) {          global $shirts;         global $prices;          foreach ($shirts => $shirt) {              $result = array_merge($shirt, $prices[$shirt_model]);          }          print_r($result);        }  shirts('product2'); 

so $shirts array like:

$shirts = array(             'option1' => array(                             'bronze' => 4,                              'silver' => 5,                              'gold' => 6,                            ),             'option2' => array(                             'bronze' => 4,                              'silver' => 5,                              'gold' => 6,                            ),         ); 

with "product2" array. call shirts(); function , pass in option append options array shirts array. approach not working? getting white screen , dont think working.

hope made sense.

as mentioned in comments convert answer.

first of need fix foreach() function as:

foreach($array $value) 

modified code:

function shirts($shirts_model)  {      global $shirts, $prices;       foreach ($shirts $key => $shirt)      {          $result[$key] = $prices[$shirts_model];     }      return $result; } 

now calling it:

$record = shirts('product2'); echo "<pre>"; print_r($record); 

error reporting:

add error_reporting on in code find out issue.

error_reporting(); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -