<?php
$fruits = ['yellow', 'green', 'orange'];
$relatedFurites = [
['yellow'=>'banana', 'green'=>'avacado'],
['yellow'=>'mango', 'green'=> 'chilli']
];
Foreach($fruits as $color){
$output[$color] = array_column($relatedFurites, $color);
}
Var_dump($output);
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- array(3) {
["yellow"]=>
array(2) {
[0]=>
string(6) "banana"
[1]=>
string(5) "mango"
}
["green"]=>
array(2) {
[0]=>
string(7) "avacado"
[1]=>
string(6) "chilli"
}
["orange"]=>
array(0) {
}
}
preferences:
151.14 ms | 408 KiB | 5 Q