I have two arrays as below.
$e which is
Array
(
[0] => AL-Alabama
[1] => AK-Alaska
)
$c which is
Array
(
[0] => Aerospace: General
[1] => Agriculture/Forestry/Fish ing/Mining: General
)
I want to create a multidimensional array using above two single arrays. I wrote below code, but just not working.
$mat1=array(array());
foreach ($e as $ee);
{foreach ($c as $cc);
{$mat1[$ee][] = $cc;}}
It gives me an output as below.
Array
(
[0] => Array
(
)
[AK-Alaska] => Array
(
[0] => Agriculture/Forestry/Fish ing/Mining: General
)
)
whereas my ideal output should be an array with combinations stored such
(AL-Alabama,Aerospace: General), (AL-Alabama,Agriculture/Forestry/Fish ing/Mining: General) and
(AK-Alaska,Aerospace: General), (AK-Alaska,Agriculture/Forestry/Fish ing/Mining: General)
Any help will be highly appreciated.
Thanks
If the thing that $e and $c have in common is the key: this does mean that $c and $e must have the same length.
<?php
$c = ['AL-Alabama', 'AK-Alaska'];
$e = ['Aerospace: General', 'griculture/Forestry/Fish ing/Mining'];
$new = [];
if (count($c) == count($e)) {
for ($i=0; $i < count($c); $i++) {
$new[$c[$i]] = $e[$i];
}
var_dump($new);
} else {
echo 'error';
}
edit: i've changed this
$new[$i] = ['e'=>$e[$i], 'c' => $c[$i]];
to
$new[$c[$i]] = $e[$i];
but both work and have an other output