Skip to content

Instantly share code, notes, and snippets.

@TakesTheBiscuit
Created February 21, 2018 17:26
Show Gist options
  • Save TakesTheBiscuit/4bf7cc075ddca312dbc086eae042f4c0 to your computer and use it in GitHub Desktop.
Save TakesTheBiscuit/4bf7cc075ddca312dbc086eae042f4c0 to your computer and use it in GitHub Desktop.
Reverse word search when reading direction is LTR
<?php
$wildcard_array = explode(' ', 'Delivered to neighbouring city signed for by github.com/TAKESTHEBISCUIT');
echo '<pre>';
print_r(reverseWildcard($wildcard_array));
echo '</pre>';
function reverseWildcard($wildcard_arr_of_words) {
$working_arr = $wildcard_arr_of_words;
$sentences = [];
if ($wildcard_arr_of_words != false) {
$count_words = count($wildcard_arr_of_words);
// so 9 words will run this 9 times..
foreach ($wildcard_arr_of_words as $word) {
$iterator = 0;
while ($iterator <= $count_words){
if (isset($working_arr[$iterator])) {
if (!isset($sentences[$iterator])) {
// init
$sentences[$iterator] = '';
}
$sentences[$iterator] .= $working_arr[$iterator];
$sentences[$iterator] .= ' '; // english has spaces after words
}
$iterator++;
}
//remove first
array_shift($working_arr);
}
if (count($sentences > 1)) {
return $sentences;
}
// FALL THROUGH
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment