php - Creating a multidimensional array -


i have 2 arrays, want put 1 multidimensional array

$array_result = array(); array1 = a,b,c,d array2 = 1,2,3,4 

the result want is

$array_result = [0] => array     (         [0] =>         [1] => 1     )  [1] => array     (         [0] => b         [1] => 2      )  etc... 

i can't work out how this. length of array1 , array2 varies dynamic data.

can point me in right direction?

try this

$arr1 = array(1,2,3,4); $arr2 = array('a','b','c','d'); $arr3 = array(); for($i = 0;$i< count($arr1);$i++) {     $arr = array();     $arr[] = $arr2[$i];     $arr[] = $arr1[$i];     array_push($arr3,$arr); } 

output

array ( [0] => array     (         [0] =>         [1] => 1     ) [1] => array     (         [0] => b         [1] => 2     ) [2] => array     (         [0] => c         [1] => 3     ) [3] => array     (         [0] => d         [1] => 4     ) ) 

codepad demo


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -