Split a string separated with spaces to an array in PHP
Use the explode()
function.
$array = explode(" ", $yourVariable);
Example:
Let’s say we have some color names separated with spaces. To convert them to the array, we should use the explode()
function, as it is presented in the following example:
<?php
$colors = "red green blue";
$array = explode(" ", $colors);
var_dump($array);
?>