Meine Aufgabe ist es zu bekommen zwei zwei Arrays erstellen:Verwenden von Variablen innerhalb Array Map-Funktion PHP
array_1 = Liste aller möglichen Optionen für die Option einer
array_2 = Liste aller möglichen Optionen für die Option zwei wenn die Option einer == array_1 [0]
diese Reihen gegeben ...
$rows = [
(object) ['option_one' => 'large mug', 'option_two' => 'one color print'],
(object) ['option_one' => 'large mug', 'option_two' => 'two color print' ],
(object) ['option_one' => 'large mug', 'option_two' => 'three color print' ],
(object) ['option_one' => 'small mug', 'option_two' => 'one color print' ],
(object) ['option_one' => 'small mug', 'option_two' => 'two color print' ],
];
Dann würde mein ausgegeben
array_1 = [ 'große Becher', 'kleiner Becher']
array_2 = [ 'ein Farbdruck', 'zwei Farbdruck', 'drei Farbdruck']
ich dies zu erreichen versucht haben, Verwendung von Array-Karten wie folgt ...
$option_one_arr = array_unique (array_map(function($row) { return $row->option_one; }, $rows));
$option_two_arr = array_unique (array_map(function($row) {
// ($option_one_arr == NULL) == TRUE
if ($row->option_one === $option_one_arr[0])
return $row->option_two;
}, $rows));
$to_render = [$option_one_arr, $option_two_arr];
echo '<pre>';
var_dump($to_render);
jedoch $ option_one_arr immer = NULL innerhalb der zweiten Array Karte trotz außerhalb der zweiten Reihe Karte korrekt.
Gedanken?