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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -