Ich habe Array mit Obst Informationen. Ein Beispiel:PHP, in einer Schleife, bestimmte Array-Werte zu einzelnen Array
Array
("
[0] => Array
("
[Id] => 58759d25bb3aa9.09061697
[Name] => Gala
[Description] => ''
[Note] => ''
) "
[1] => Array
("
[Id] => 587589476029e8.93893728
[Name] => Admiral
[Description] => ''
[Note] => ''
) "
[2] => Array
("
[Id] => 5875b2a1865f50.73423631
[Name] => Elstar
[Description] => ''
[Note] => ''
) "
) "
Array
("
[0] => Array
("
[Id] => 5875b2a1865f50.73423631
[Name] => Bing-Cherries
[Description] => ''
[Note] => ''
) "
[1] => Array
("
[Id] => 5875b2c6210de4.91470020
[Name] => Van-Cherries
[Description] => ''
[Note] => ''
) "
[2] => Array
("
[Id] => 5875b911eeddb1.20644994
[Name] => Reiner-Cherries
[Description] => ''
[Note] => ''
) "
) "
In einer Schleife, kann ich den Array-Typen wie Apfel zuzugreifen, Kirschen, usw. Jedes Array eine eindeutige Nummer als Typ hat. Beispiel Kirschen ist ($sConfigType == 1)
.
Jetzt möchte ich, wenn die Frucht "Kirschen" kommt, um die Array-Werte zu dem einzelnen Array zu machen.
Zum Beispiel:
Array
(
[0] => Array
(
[id] => 58759d25bb3aa9.09061697
[name] => Gala
[description] => ''
[note] => ''
)
[1] => Array
(
[id] => 587589476029e8.93893728
[name] => Admiral
[description] => ''
[note] => ''
)
[2] => Array
(
[id] => 5875b2a1865f50.73423631
[name] => Elstar
[description] => ''
[note] => ''
)
)
Array
(
[0] => Array
(
[id] => 5875b2a1865f50.73423631
[name] => Bing-Cherries
[description] => ''
[note] => ''
)
)
Array (Cherries)
(
[0] => Array
(
[id] => 5875b2c6210de4.91470020
[name] => Van-Cherries
[description] => ''
[note] => ''
)
)
Array (Cherries)
(
[0] => Array
(
[id] => 5875b911eeddb1.20644994
[name] => Reiner-Cherries
[description] => ''
[note] => ''
)
)
So habe ich versucht, es zu implementieren, funktioniert leider nicht:
protected function _splitFruitArray($sConfig)
{
if (is_array($sConfig) || is_object($sConfig)) {
$sConfigType = $sConfig->type;
$sOther = array();
foreach ($sConfig as $sKey => $sVal) {
if ($sConfigType == 1) { // if fruit is cherries split values to single array
foreach ($sVal as $iKey => $iVal) {
$arr[$iKey] = $iVal;
}
} else {
$sOther[$sKey] = $sVal;
}
array_push($sOther, $arr);
}
$sConfig = $sOther;
}
print_r($sConfig);
return $sConfig;
}
Leider funktioniert nicht. Die Schlüssel enthalten keine Array-Typ-Informationen, siehe oben meinen Code. –
Was ist der Wert von 'echo sConfigType;'? –
eindeutige ganze Zahlen, ($ sConfigType == 1) ist Kirschen. –