In PHP, strings and arrays are transferred to each other
Splitting a string into an array explode ()--(split in other languages)
Concatenate an array into a string implode ()
<?PHP$test= ' I am Tommy.huang '; $result 1=Explode(‘ ‘,$test); Print_r($result 1); Echo' <br>-------------<br> '; $result 2=Explode(‘,‘,$test); Print_r($result 2); Echo' <br>-------------<br> '; $test _array1=Array( ' Apple ', ' pear ', ' orange ', ); $test _array2=Array( ' Apple ', ); $result 3=implode('-A ',$test _array1); $result 4=implode('-A ',$test _array2); Print_r($result 3); Echo' <br>-------------<br> '; Print_r($result 4);
The results are as follows:
Attention:
The explode () function splits a string by a given flag, and if the string does not have the flag, the result is not split , as in the second row of the result;
The implode () function is a string that links the elements of an array to a given flag, and when the array has only one element, there is no connection effect , as in the fourth row of the result.
PHP explode () and implode () methods