Jürgen Paul
Jürgen Paul

Reputation: 15007

Check if an array only contains one key/value

$foo = array('one');
$foofoo = array('onekey' => 'onevalue');

How do you check if an array contains only one key?

Upvotes: 12

Views: 27488

Answers (1)

John Conde
John Conde

Reputation: 219804

count() will tell you how many elements are in an array

if (count($foo) === 1) {
    echo 'This array contains one value';
}

Upvotes: 33

Related Questions