Break the word in php letters

I want to take a string from a form and then split it into an array of characters using PHP, for example:

$a = 'professor';
$b[0] == 'p';
$b[1] == 'r';
$b[2] == 'o';
.
.
.
.
.
$b[8] = 'r';
+3
source share
4 answers

You do not need to do this. In PHP, you can access your characters directly from a string, as if it contained an array:

$var = "My String";
echo $var[1]; // Will print "y".
+26
source
str_split($word);

This is faster than accessing $ word as an array.(And also better if you can iterate over it with foreach().) Documentation .

+9
source

, , :

$b = str_split($a)

$a [0], $a [1] ..

+3

, , ASCII ().

+1

Source: https://habr.com/ru/post/1706233/


All Articles