PDA

Click to See Complete Forum and Search --> : How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")


jcavard
Apr 12th, 2006, 08:50 AM
So?

I know there is a way but I just can igure out how to do this...

..:RUDI:..
Apr 12th, 2006, 09:46 AM
$var = "string";
$arr = str_split($var);

Hope this helps

jcavard
Apr 12th, 2006, 10:28 AM
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

function str_split($var)
{
$array = array();
for($i = 0; $i < strlen($var); $i++){
$array[] = substr($var, $i, 1);
}
return $array;
}

penagate
Apr 12th, 2006, 07:43 PM
What do you need this for?

You can use a string as an array, if you want.

$var = "string";
echo $var[3];

Inuyasha1782
Apr 12th, 2006, 09:01 PM
Or you could use explode:

$var = "string";
$var = explode($var, "");