Re: Count empty array
| From: | tg-php at gryffyndevelopment dot com | Date: | Thu, 21 Dec 2006 21:52:49 +0000 |
| Subject: | Re: Count empty array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-246141@lists.php.net to get a copy of this message | ||
Not sure why it does it, but doesn't seem to be a huge deal. I'm guessing it's
because an empty string is still a string. It's not null.
Anyway, it's documented at:
http://us3.php.net/manual/en/function.explode.php
A user writes:
"If you split an empty string, you get back a one-element array with 0 as the key and an empty
string for the value."
-TG
= = = Original message = = =
I'm wondering why this is.
$data = "";
$array = explode(",",$data);
$count = count($array);
$count will = 1
$data = "Test";
$array = explode(",",$data);
$count = count($array);
$count will = 1
$data = "Test,Test";
$array = explode(",",$data);
$count = count($array);
$count will = 2
Why doesn't the first one give me an answer of 0 instead of 1. I know
I could do a IF $data == "[empty]" and then not count if its empty
and just set it to 0, but am wondering if there was a better way.
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.