This should be easy, but I can´t seem to get it to work. I have an multidimensional array and I wan´t iterate trough the array and check for a specific value. If the value equals a string then echo out a value of the array.
Here is the array and two values (the full array has a lot more):
$users = array(
"username01" => array("fullname" => "Firstname Lastname",
"status" => "Online"),
"username02" => array("fullname" => "Firstname Lastname",
"status" => "Offline")
);
I wan't to echo
out the Full name of each user that is "Online". Here is what I'm using today but it's not working:
$string = "Online";
foreach ($users as $username => $data) {
$fullname = $data["fullname"];
$status = $data["status"];
echo $status."= ";
if ($status == $string) {
echo "Yes";
} else {
echo "No";
}
echo "<br>";
}
If I echo out $fullname
and $status
the correct data is printed out. But for some reason the IF statement is not working. If the user is Offline the echo is "No", but if the user is Online there is no echo at all.
EDIT - Solved
Updated the array keys with quotes and $data[...] as was suggested below. I found a typo that was causing a false output. Thanks for all the help.