i have two arrays like
Array1
(
[0] => 1
[1] => 2
[2] => 3
)
Array2
(
[0] => a
[1] => b
[2] => c
)
i want make
Array3 Like
(
[0] => ([0]=>1 [1]=>a)
[1] => ([0]=>2 [1]=>b)
[2] => ([0]=>3 [1]=>c)
)
Using SPL's MultipleIterator
$arr1 = [1, 2, 3];
$arr2 = ['a', 'b', 'c'];
$mi = new MultipleIterator();
$mi->attachIterator(new ArrayIterator($arr1));
$mi->attachIterator(new ArrayIterator($arr2));
$result = array();
foreach($mi as $details) {
$result[] = $details;
}
var_dump($result);
This is definitely not the prettiest way to do it, but since you haven't supplied any attempted code, I doubt anybody wants to bother with this question so here:
NOTE: As stated in the comments, you're going to have to make sure the two arrays are the same length and sort that out yourself.
$one = array(
'1',
'2',
'3'
);
$two = array(
'a',
'b',
'c'
);
$derp = array();
foreach($one as $key => $val) {
$derp[] = array(
$val,
$two[$key]
);
}
?>
Which returns
Array
(
[0] => Array
(
[0] => 1
[1] => a
)
[1] => Array
(
[0] => 2
[1] => b
)
[2] => Array
(
[0] => 3
[1] => c
)
)