Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an array only contains one key/value

Tags:

arrays

php

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

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

like image 805
Jürgen Paul Avatar asked Apr 30 '12 02:04

Jürgen Paul


1 Answers

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

if (count($foo) === 1) {
    echo 'This array contains one value';
}
like image 152
John Conde Avatar answered Nov 01 '22 01:11

John Conde