note 33528 deleted from function.count by didou

From: Date: Sun, 07 Dec 2003 03:06:54 +0000
Subject: note 33528 deleted from function.count by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-61569@lists.php.net to get a copy of this message
Note Submitter: ian@ianco.co.uk ---- Counting arrays. The webmaster post from Apr-2002 could give the impression that count($array) will give the number of dimensions in the array. This is not true, since after $settings[0][0][0] = 128; the following still holds: echo count($settings) // returns 2 The following painful definition seems to work for me (so far!): Let $var be a variable (which may be an array). Let <S> be a sequence of zero or more of [key] . ( So $var<S> could be $var[0] , or $var['z'][3]['dolphins'] , or just $var ). Then count($var<S>) will return EITHER if there are any, the number of set elements whose name is in the form $var<S>[anotherkey] ELSE if $var<S> exists and is set, 1 ELSE 0 Maybe someone can express this better ;-)

« previous php.notes (#61569) next »