In PHP, how do i convert:
$result = abdcef;
into an array that's:
$result[0] = a;
$result[1] = b;
$result[2] = c;
$result[3] = d;
In PHP, how do i convert:
$result = abdcef;
into an array that's:
$result[0] = a;
$result[1] = b;
$result[2] = c;
$result[3] = d;
$result = "abcdef";
$result = str_split($result);
There is also an optional parameter on the str_split function to split into chunks of x characters.
You can use the str_split() function:
$value = "abcdef";
$array = str_split($value);
If you wish to divide the string into array values of different amounts you can specify the second parameter:
$array = str_split($value, 2);
The above will split your string into an array in chunks of two.
Don't know if you're aware of this already, but you may not need to do anything (depending on what you're trying to do).
$string = "abcdef";
echo $string[1];
//Outputs "b"
So you can access it like an array without any faffing if you just need something simple.