3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $str = "Hello World";$spaceCount = substr_count($str, " "); $letterIndx = 0; // count number of spaces and then loop for($i=0; $i<=$spaceCount; $i++) { // get space positions $spaceIndx = strpos($str, " ", $letterIndx); // assign word by specifying start position and length if ($spaceIndx == 0) { $word = substr($str, $letterIndx); } else { $word = substr($str, $letterIndx, $spaceIndx - $letterIndx); } // push word into array $myArray[] = $word; // get first letter after space $letterIndx = $spaceIndx + 1; } // reverse the array $reverse = array_reverse($myArray); // echo it out foreach($reverse as $rev) { echo $rev." "; } ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
World Hello