Re: Explode a variable into each character
| From: | Philip Olson | Date: | Fri, 23 Feb 2001 19:41:17 +0000 |
| Subject: | Re: Explode a variable into each character | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41361@lists.php.net to get a copy of this message | ||
If $string is a string, like :
$string = '312';
Then one can do :
$string[0]; // 3
$string[1]; // 1
$string[2]; // 2
Note, '312' is a string and will work using above but if we define 312 as
an integer like :
$string = 312;
Then $string[0] will not "work" and it'll need to be juggled as a string
first, see :
http://www.php.net/manual/en/language.types.type-juggling.php
Also, if you want to create an array and not do the above then check
out the following, an example exists to do this :
http://www.php.net/manual/en/function.preg-split.php
Regards
Philip Olson
http://www.cornado.com/
On Fri, 23 Feb 2001, Brandon Orther wrote:
> Hello,
>
> I have a string of 1034 and I want to have an array that has each number in
> an element.(ex: num[0] = 1, num[1] = 0, num[2] = 3 num[3] = 4) Is there a
> way to explode a string by each character?
>
> Thank you,
>
> --------------------------------------------
> Brandon Orther
> WebIntellects Design/Development Manager
> brandon@webintellects.com
> 800-994-6364
> www.webintellects.com
> --------------------------------------------
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>