First, it seems that you have a different array for the Name, I wonder why you don't have something like:
["Person"] => array(11) {
["id"] => int(38482818123)
["weight"] => int(140)
["height"] => int(65)
["firstname"] => string(4) "John"
["lastname"] => string(5) "Smith"
}
As per that case, the array index with the key "firstname" , "lastname" might not be set for some person. So you can check if that index is set using
isset();
function
Try:
foreach($personArray as $person)
{
if (isset($person['firstname']) && isset($person['lastname']) ) // You may use or as well ||
{
echo "<img src='image-a.png'>";
}
else
{
echo "<img src='image-b.png'>";
}
// Or as a short hand if statement:
echo (isset($person['firstname'])&& isset($person['lastname'])) ? "<img src='image-a.png'>" : "<img src='image-b.png'>";
}
Edit: 1
You still seem to be using two different arrays: Person and Name. Doing this, you cannot say which particular person has the name values or not:
For eg: if you have 10 persons and have the Name array with firstname, lastname for just 7 person then you will have person[0], person[1].....person[9] and Name[0]...Name[6].
As per your construct, there is no any reference / link between the Person and Name array. Suppose 1st person has Name, then Person[0] and Name[0] would represent the same person. But if the first 3 Person do not have Name, then Person[3] will have Name[0]...and so on, hence, it is not possible to identify to which Person does a particular Name array belong to. And Note: you cannot use Name["firstname"] inside the foreach() of Person. Because, your name array would be of the form Name[0]["firstname"], Name[0]["lastname"] and so on.
Bottom Line:
If possible, try to use / include the firstname, lastname in the Person array itself. That way, when iterating / looping through the Person array using foreach() you can check if each of these person have firstname , lastname or not: Hope this is clear.
!empty($person['Name'])