given this example below,
//Array A
$arrayA = [
'a',
'b',
'c'
];
//Array B
$arrayB = [
'x',
'y',
'z'
];
how to loop those two arrays if i want to have the final combined array like this ?
$combinedArray = [
['a','x'],
['a','y'],
['a','z'],
['b','x'],
['b','y'],
['b','z'],
['c','x'],
['c','y'],
['c','z']
];
as you can see the output above,each element of Array A ,has an element of Array B
here's my solution
$combined = [];
foreach ($arrayA as $a) {
for ($i=0; $i < sizeof($arrayB); $i++) {
$combined[] = [
$a,
$arrayB[$i]
];
}
}