|
-
Apr 12th, 2006, 08:50 AM
#1
Thread Starter
Fanatic Member
How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")
So?
I know there is a way but I just can igure out how to do this...
-
Apr 12th, 2006, 09:46 AM
#2
Hyperactive Member
Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")
PHP Code:
$var = "string";
$arr = str_split($var);
Hope this helps
-
Apr 12th, 2006, 10:28 AM
#3
Thread Starter
Fanatic Member
Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")
yes thank you, it helped, but this is new to PHP5, and I've been using php for a while and I'm sure there was another trick.. but anyway, thanks
since I am still working with php4, I figured out a function myself
PHP Code:
function str_split($var)
{
$array = array();
for($i = 0; $i < strlen($var); $i++){
$array[] = substr($var, $i, 1);
}
return $array;
}
-
Apr 12th, 2006, 07:43 PM
#4
Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")
What do you need this for?
You can use a string as an array, if you want.
PHP Code:
$var = "string";
echo $var[3];
-
Apr 12th, 2006, 09:01 PM
#5
Frenzied Member
Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")
Or you could use explode:
PHP Code:
$var = "string";
$var = explode($var, "");
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|