I know how to use the explode function. But i want to explode every character in a string (with out using a separator). for example, make: "some string" into an array: Array ( [0] => s [1] => o [2] => m [3] => e [4] => [5] => s [6] => t [7] => r [8] => i [9] => n [10] => g ) I want to explode everything (not just at the separator). how can this be done??
brendandonhue's answer is correct, but you can also use something like this: $string = 'your string'; for($i=0;$i< strlen($string);$i++){ $array[] = substr($string, $i , 1); } PHP:
what exactly do you need to do this for? maybe someone here can think of a better way of doing it if you explain what you need it for?
There's no reason to reinvent the wheel (and use the overhead of a loop or the regular expression engine.) Accessing characters in a string like array elements is already built in to PHP.
I was going to answer the same way brendandonhue did, but I checked out str_split that nico_swd posted, and it does exactly this, and lets you choose how many characters to put in each element.