3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getBaconSentences($len) { $paragraph = ""; $words = array( "upper" => array("The", "A", "One", "Some", "Any"), "lower" => array("the", "a", "one", "some", "any"), "noun" => array("boy", "girl", "dog", "town", "car"), "verb" => array("drove", "jumped", "ran", "walked", "skipped"), "prep" => array("to", "from", "over", "under", "on"), "adj" => array('tiny', 'freezing', 'lazy','boiling','filthy') ); $structures = array( array('upper', 'noun', 'verb', 'prep', 'lower', 'noun'), array('upper', 'noun', 'verb', 'prep', 'lower', 'adj', 'noun') ); while($len--) { $sentence = array(); $randStructure = array_rand($structures); for($i=0; $i<count($structure[$randStructure]); $i++) { echo json_encode($randStructure); $word = ' ';//array_rand($words[$randStructure[$i]]); $sentence[] = $word ; } $paragraph .= implode(" ", $sentence) . '. '; } return $paragraph; } echo getBaconSentences(10);

preferences:
41.9 ms | 402 KiB | 5 Q