Array Filtern bei mehreren Werten innerhalb eines Array
Hallo zusammen,
ich habe folgendes Array:
Array ( [resource] =>
Array ( =>
Array ( [ID] => 3 [EN] => Registration [EN_Expl] => Registration Header [EN_Placeholder] => Registration ) [1] =>
Array ( [ID] => 4 [EN] => Gender [EN_Expl] => We need this gender information, to bring you to the right teams. [EN_Placeholder] => Gender ) [2] =>
Array ( [ID] => 5 [EN] => Firstname [EN_Expl] => The firstname will be neccessary for a correct registration. [EN_Placeholder] => Your firstname ) [3] =>
Array ( [ID] => 6 [EN] => Familyname [EN_Expl] => The firstname will be neccessary for a correct registration. [EN_Placeholder] => Your familyname ) ) )
Ich stehe gerade offenbar ein wenig auf dem Schlauch.
Ich möchte gern dieses Array folgendermaßen zerlegen:
Wenn der ID Wert des Array 3 ist, dann gib mir den Wert für EN_Expl.
Doch so richtig fällt mir gerade kein Weg ein, wie ich da rankomme.
Könnt ihr mir bitte auf die Sprünge helfen?
Danke und Grüße
René
ich habe folgendes Array:
Array ( [resource] =>
Array ( =>
Array ( [ID] => 3 [EN] => Registration [EN_Expl] => Registration Header [EN_Placeholder] => Registration ) [1] =>
Array ( [ID] => 4 [EN] => Gender [EN_Expl] => We need this gender information, to bring you to the right teams. [EN_Placeholder] => Gender ) [2] =>
Array ( [ID] => 5 [EN] => Firstname [EN_Expl] => The firstname will be neccessary for a correct registration. [EN_Placeholder] => Your firstname ) [3] =>
Array ( [ID] => 6 [EN] => Familyname [EN_Expl] => The firstname will be neccessary for a correct registration. [EN_Placeholder] => Your familyname ) ) )
Ich stehe gerade offenbar ein wenig auf dem Schlauch.
Ich möchte gern dieses Array folgendermaßen zerlegen:
Wenn der ID Wert des Array 3 ist, dann gib mir den Wert für EN_Expl.
Doch so richtig fällt mir gerade kein Weg ein, wie ich da rankomme.
Könnt ihr mir bitte auf die Sprünge helfen?
Danke und Grüße
René
Please also mark the comments that contributed to the solution of the article
Content-Key: 369404
Url: https://administrator.de/contentid/369404
Printed on: April 18, 2024 at 14:04 o'clock
3 Comments
Latest comment
<?php
$arr = <DEIN ARRAY>;
foreach($arr['resource'] as $key => $value){
if($value['ID'] == 3){
echo $value['EN_Expl'];
break;
}
}
?>
Servus,
alternativ als Ergänzung geht es auch ohne Schleife, mit array_search
Grüße Uwe
alternativ als Ergänzung geht es auch ohne Schleife, mit array_search
$arr = [DEIN ARRAY HIER];
// Suche nach ID mit der Nummer X
$search = 3;
// array filtern nach IDs mit der Nummer (gibt key des matching items zurück)
$result = array_search($search,array_column($arr['resource'],"ID"));
// Wenn ein Item gefunden wurde gebe den entsprechenden Eintrag aus
if($result !== false){
echo $arr['resource'][$result]['EN_Expl'];
}else{
echo "not found";
}