php - Adding datas into an array / coupling arrays -
i haves 2 arrays :
the first 1 :
$positions = array(0 => array(6.35,3.93), 1 => array(16.85,3.93), 2 => array(6.35,10.9), 3 => array(16.85,10.9), 4 => array(6.35,18.48), 5 => array(16.85,18.48), 6 =>a rray(6.35,25.45), 7 => array(16.85,25.45));
the second 1 :
$coupons = array ( [0] => ngp7xdaerk [1] => lntkt38dxj [2] => ubg2fplvnx [3] => ymmko6ef16 [4] => zszcasrwrj [5] => cl6uj1a7vs [6] => lrjc5vnpl6 [7] => mexuzqbols ) ;
i'd merge 2 arrays have :
array(0 => array(6.35,3.93, ngp7xdaerk ), 1 => array(16.85,3.93, lntkt38dxj ), ...
i'm not familiar handling arrays that, i've heard of array_push , array_merge, know have use foreach loop in order avoid keys added, don't know how make concrete such informtion ^^
could guys me ? :)
thanks lot :)
assuming arrays both same length. use this:
$positions = array(0 => array(6.35,3.93), 1 => array(16.85,3.93), 2 => array(6.35,10.9), 3 => array(16.85,10.9), 4 => array(6.35,18.48), 5 => array(16.85,18.48), 6 => array(6.35,25.45), 7 => array(16.85,25.45)); $coupons = array ( 0 => 'ngp7xdaerk', 1 => 'lntkt38dxj', 2 => 'ubg2fplvnx', 3 => 'ymmko6ef16', 4 => 'zszcasrwrj', 5 => 'cl6uj1a7vs', 6 => 'lrjc5vnpl6', 7 => 'mexuzqbols' ) ; $result = array(); foreach($positions $i=>$pos ) { $result[$i] = array_merge($pos, (array)$coupons[$i]); } print_r($result);
result:
array ( [0] => array ( [0] => 6.35 [1] => 3.93 [2] => ngp7xdaerk ) [1] => array ( [0] => 16.85 [1] => 3.93 [2] => lntkt38dxj ) [2] => array ( [0] => 6.35 [1] => 10.9 [2] => ubg2fplvnx ) [3] => array ( [0] => 16.85 [1] => 10.9 [2] => ymmko6ef16 ) [4] => array ( [0] => 6.35 [1] => 18.48 [2] => zszcasrwrj ) [5] => array ( [0] => 16.85 [1] => 18.48 [2] => cl6uj1a7vs ) [6] => array ( [0] => 6.35 [1] => 25.45 [2] => lrjc5vnpl6 ) [7] => array ( [0] => 16.85 [1] => 25.45 [2] => mexuzqbols ) )
Comments
Post a Comment