Trouver la valeur dans un tableau (array) : Illegal string offset
Bonjour,
J'ai un array qui contient les identifications de certains utilisateurs.
J'ai les informations sur l'adresse et le nom de la famille d'un utilisateur et il faut que je le trouve son ID.
J'ai commencé par une boucle [foreach], mais j'ai bloqué par un message d'erreur.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| error_reporting(E_ALL);
ini_set("display_errors", 1);
$dataIdentity = [
[
"Id" => 125,
"LastName" => "tata",
"Street" => "Adlershof",
"City" => "Berlin",
"CodePostal" => "10623",
"Country" => "Allemagne"
],
[
"Id" => 258,
"LastName" => "tata",
"Street" => "st-denis",
"City" => "paris",
"CodePostal" => "75000",
"Country" => "France"
],
[
"Id" => 859,
"LastName" => "TOPO",
"Street" => "st-paul",
"City" => "paris",
"CodePostal" => "75000",
"Country" => "France"
],
[
"Id" => 159,
"LastName" => "tata",
"Street" => "st-paul",
"City" => "paris",
"CodePostal" => "75000",
"Country" => "France"
]
];
$countrySearche = "France";
$codePostalSearche = "75000";
$citySearche = "paris";
$streetSearche = "st-denis";
$lastNameSearche = "tata";
//trouver la bon array
foreach ($dataIdentity as $keyCountry => $value) {
if ($value["Country"] === $countrySearche) {
echo "<p>" . $keyCountry . "</p>";
foreach ($dataIdentity[$keyCountry] as $keyCodePostal => $valueCodePostal) {
if ($valueCodePostal["CodePostal"] === $codePostalSearche) {
echo "<p>" . $keyCodePostal . "</p>";
}//CodePostal
}//CodePostal
}//Country
}
// trouver le bon id
$searcheID;
die("wwwww"); |
et voici le message d'erreur :
Citation:
Warning: Illegal string offset 'CodePostal' in C:\sites\test\scripts\array_value_find.php on line 52
voici la ligne 52 :
Code:
if ($valueCodePostal["CodePostal"] === $codePostalSearche) {
Est-ce que vous pouvez m'aider pour corriger cette erreur.
Merci