My script outputs an array:
$person = array(
    'name' => 'bob',
    'age' => '27',
    'sex' => 'male',
    'weight' => 'fat'
    // ...etc.
);
Sometimes the keys in $person have no values - and I want to check for this. However, I don't give a chicken nugget about $person['age'] or $person['weight'], I only want to check the other keys in the array aren't empty:
foreach ($person as $key => $value) {
    if ( $key != 'age' || $key != 'weight' ) {
        if ( empty($value) ) {
            echo 'you dun goofed';
        }
    }
}
Why isn't this working?
This matches all keys:
if ( $key != 'age' || $key != 'weight' )
You probably want:
if ( $key != 'age' && $key != 'weight' )
or something like (scales a bit better...):
if (!in_array($key, array('age', 'weight')))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With