I am sure this is really easy, but I can't find the right function.
I have two arrays, one for x values, one for y and now I want to combine them xyxyxy.
for example:
$x = array( 0=>10, 1=>20, 2=>30 );
$y = array( 0=>15, 1=>25, 2=>35 );
Mixed would leave:
$xy = array( 0=>10, 1=>15, 2=>20, 3=>25, 4=>30, 5=>35 );
If you can't rely on the keys matching across both arrays you could try something like the following
$x = array("XA" => "X 1", "XB" => "X 2", "XC" => "X 3");
$y = array("YA" => "Y 1", "YB" => "Y 2", "YC" => "Y 3");
$xy = array();
foreach($x as $k => $v) {
$xy[] = array_shift($x);
$xy[] = array_shift($y);
}
$x = array( 0=>10, 1=>20, 2=>30 );
$y = array( 0=>15, 1=>25, 2=>35 );
$xy = array();
for ($i=0; $i<count(x); $i++) {
$xy[] += $x[i];
$xy[] += $y[i];
}
try this
$a = array_merge($x, $y);
asort($a);
print_r($a);
精彩评论