php - Need some help iterating over this two arrays -


i have 2 arrays:

$arr1['product_detail'] = array(     "26" => array("blue", "green"),     "28" => array("s") ); $arr2['variation'] = array(     "pupc" => array("123456", "654321"),     "pprice" => array(1, 2),     "pqty" => array(10, 11) ); 

i need build new array containing values based on position, less said:

$arr3 = array(     array("blue", "s", "123456", 1, 10),     array("green", "s", "654321", 2, 11) ); 

if notice mix position of both original arrays. think in like:

foreach ($arr2 $key => $value) {     foreach ($value $key1 => $value1) {         foreach ($value1 $key2 => $value2) {             foreach ($arr1 $key3 => $value3) {                 echo $key3;             }         }     } } 

but it's ugly , think better ways this, help?

it idea use function

function array_addition($main_array, $new_array) {   foreach ($new_array $aitem) {     ($i=0;$i<=1;$i++) {       $main_array[$i][] = current($aitem) ? current($aitem) : reset($aitem);       next($aitem);     }   }   return $main_array; }  $arr3 = array();  $arr3 = array_addition($arr3, $arr1['product_detail']); $arr3 = array_addition($arr3, $arr2['variation']); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -