php method to convert array by space: 1. Create a new php file; 2. Save the string to be split in the $str variable; 3. Use the explode() function to convert the string in the previous step to an array with spaces. The split and returned array is stored in the $res variable; 4. Use print_r() to print the array on the page.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
php How to convert a string into an array by spaces?
Create a new PHP file named test.php to explain how PHP splits a string into an array by spaces.
In the test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid garbled characters when the page outputs Chinese.
In the test.php file, save the string to be split in the $str variable.
In the test.php file, use the explode() function to split the string in the previous step by spaces, and the returned array is stored in the $res variable.
In the test.php file, use print_r() to print the array on the page.
Open the test.php file in the browser to view the results.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert array by space in php. For more information, please follow other related articles on the PHP Chinese website!