Home > Article > Backend Development > How to convert php string to array
php string to array method: First create a PHP sample file; then use the [$arr1 = str_split($str);] method to convert the string [$str] into an array.
Recommended: "PHP Video Tutorial"
PHP Convert string to array str_split
Convert a continuous string into a single character array
Example:
<?php $str = 'abcde'; $arr1 = str_split($str); print_r($arr1); ?>
The output result is as follows:
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e )
The difference from explode is: The first parameter of explode must pass a splitting character (such as:, | space) to split; str_split splits directly
The above is the detailed content of How to convert php string to array. For more information, please follow other related articles on the PHP Chinese website!