i am receiving the name
from the $request
in php.I want to do something like to add all the letters of the name in the array during the request e.g
$name=$_request['name'];
say $name='test';
i want to save it in an array in this format as array("t","e","s","t")
.
how can i do it ?
Asked
Active
Viewed 221 times
1

qadeerkhan
- 85
- 11
-
possible duplicate of [PHP: Split string into array, like explode with no delimiter](http://stackoverflow.com/questions/2170320/php-split-string-into-array-like-explode-with-no-delimiter) – HamZa Oct 10 '13 at 13:18
5 Answers
1
It may be sufficient for you to access the string directly as an array, without the need to format the data:
$a = 'abcde';
echo $a[2];
Will output
c
However you won't be able to perform some array operations, such as foreach

Buchow_PHP
- 410
- 3
- 10
0
see the php site
so it would be like
$name= 'test';
$arr1 = str_split($name);
would result in a array like:
Array
(
[0] => t
[1] => e
[2] => s
[3] => t
)

mariomario
- 660
- 1
- 9
- 29
0
Here you go
$i = 0;
while(isset($name[$i])) {
$nameArray[$i] = $name[$i];
$i++;
}

om_deshpande
- 665
- 1
- 5
- 16
0
Try this:
$letters = array();
for (int $i=0; $i < strlen($name); $i++){
$letters[] = $name[$i];
}
and you can access it with:
for (int $i=0; $i < strlen($letters); $i++){
$letters[$i];
}

Ed_
- 973
- 11
- 25