<?php $str = "This is a string"; $words = explode(" ", $str); $spaces=array(); $others=array(); foreach($words as $word) { if($word==' ') { array_push($spaces,$word); } else { array_push($others,$word); } } var_export([ 'words' => $words, 'spaces' => $spaces, 'others' => $others ]);
You have javascript disabled. You will not be able to edit any code.