Combine multiple array into one array using php -
I am trying to create an array with multiple arrays, individual arrays have the key name not the array of the new array The key will be
for example:
$ product_name = array ('0' => 'product1', '2' = & gt; 'product2 '); $ Product_id = array ('0' => 1 ',' 2 '= & gt;' 2 '); I want to show the two arrays as below $ newarray = array ("0" => array ('product_id' =) & gt; 1, 'product_name' = & gt; 'product1'), "1" => array ('product_id' => 2, 'product_name' = & gt; 'product2'),) ; Code:
$ product_name = array ('0' => 'product1', '2' => 'product2'); $ Product_id = array ('0' => 1 ',' 2 '=> 2'); $ New_array = array (); $ {$ new_array [] = array ('product_id' = & gt; $ product_id [$ s], 'product_name' = & gt; $ product_name [$ key]); Foreach (array_kiz ($ product_id) as the $ key); } Print_r ($ new_array); Array ([0] = & gt; array ([product_id] => 1 [product_name] Result: < code> => product 1) [1] => Array ([product_id] => 2 [product_name] => Product 2)) < / html>
Comments
Post a Comment