3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splort($org, $stop_words) { $words = explode(' ', $org); $abbrevs = array(''); foreach ($words as $word) { if (in_array($word, $stop_words)) { // create a new set of abbreviations with this word's initial included $new_abbrevs = array(); foreach ($abbrevs as $abbrev) { $new_abbrevs[] = $abbrev . $word[0]; } // merge the arrays $abbrevs = array_merge($abbrevs, $new_abbrevs); } else { // add the initial to each abbreviation foreach ($abbrevs as &$abb) { $abb .= $word[0]; } } } return $abbrevs; } $stop_words = array('of', 'and'); print_r(splort('State Bank of and India', $stop_words));

preferences:
23.65 ms | 407 KiB | 5 Q