Fwd: [PHP] Count the Number of Elements Using Explode



---------- Forwarded message ----------
From: Kyle Terry <kyle@xxxxxxxxxxxxx>
Date: Fri, Oct 31, 2008 at 9:31 AM
Subject: Re: [PHP] Count the Number of Elements Using Explode
To: Alice Wei <ajwei@xxxxxxxxxxxxx>


I would use http://us2.php.net/manual/en/function.array-count-values.php


On Fri, Oct 31, 2008 at 9:29 AM, Alice Wei <ajwei@xxxxxxxxxxxxx> wrote:


Hi,

I have a code snippet here as follows:

$message="1|2|3|4|5";
$stringChunks = explode("|", $message);

Is it possible to find out the number of elements in this string? It seems
that I could do things like print_r and find out what is the last element of
$stringChunks is, but is there a way where I can use code from the two lines
and have it print out 5 as the number of elements that contains after the
splitting?

Or, am I on the wrong direction here?

Thanks in advance.

Alice
_________________________________________________________________
Check the weather nationwide with MSN Search: Try it now!
http://search.msn.com/results.aspx?q=weather&FORM=WLMTAG
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Kyle Terry | www.kyleterry.com



--
Kyle Terry | www.kyleterry.com


Relevant Pages

  • If working upside down
    ... In the following code snippet: ... If the pw is empty, ... Screen output, with a correctly entered pw is: ...
    (comp.lang.php)
  • Re: Fwd: [PHP] Count the Number of Elements Using Explode
    ... [PHP] Count the Number of Elements Using Explode ... I have a code snippet here as follows: ... Is it possible to find out the number of elements in this string? ... array_count_values returns an array which tells you how often each VALUE was found in that array. ...
    (php.general)
  • Re: php/mysql puzzler
    ... different versions of PHP my server and my host's server were using. ... (I've added a larger code snippet below.) ... php or mysql setting that may have unintended consequence elsewhere. ...
    (comp.lang.php)
  • Re: [PHP] Storing objects in sessions recursively
    ... Stut wrote: ... php -r ' ... this only outputs 'foo' once. ...
    (php.general)
  • Re: Object of class Person could not be converted to string
    ... PHP has been lousy at maintaining backward compatibility. ... Objects are always converted to the string "Object". ... there's no reasonable gain in usability by forcing it ...
    (comp.lang.php)