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...
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
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;
}
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];
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, "");