fork download
  1. <?php
  2.  
  3. $string="Merry alone do it burst me songs. Sorry equal charm joy her those folly ham. In they no is many both. Recommend new contented intention improving bed performed age. Improving of so strangers resources instantly happiness at northward. Danger nearer length oppose really add now either. But ask regret eat branch fat garden. Become am he except wishes. Past so at door we walk want such sang. Feeling colonel get her garrets own.";
  4.  
  5. $splited = preg_split('/[ ,.!?]/', $string, -1, PREG_SPLIT_NO_EMPTY);
  6.  
  7.  
  8.  
  9. foreach ($splited as $key => $word) {
  10. $firsLetters[] = lcfirst($word[0]);
  11. $words[] = lcfirst($word);
  12.  
  13. }
  14.  
  15. foreach ($firsLetters as $firstLetter) {
  16. foreach ($words as $word) {
  17. if ($firstLetter == $word[0] && !in_array($word, $combined[$firstLetter])) {
  18. $combined[$firstLetter][] = $word;
  19.  
  20. }
  21. }
  22. }
  23.  
  24. var_dump($combined);
Success #stdin #stdout #stderr 0.02s 23876KB
stdin
Standard input is empty
stdout
array(19) {
  ["m"]=>
  array(3) {
    [0]=>
    string(5) "merry"
    [1]=>
    string(2) "me"
    [2]=>
    string(4) "many"
  }
  ["a"]=>
  array(6) {
    [0]=>
    string(5) "alone"
    [1]=>
    string(3) "age"
    [2]=>
    string(2) "at"
    [3]=>
    string(3) "add"
    [4]=>
    string(3) "ask"
    [5]=>
    string(2) "am"
  }
  ["d"]=>
  array(3) {
    [0]=>
    string(2) "do"
    [1]=>
    string(6) "danger"
    [2]=>
    string(4) "door"
  }
  ["i"]=>
  array(6) {
    [0]=>
    string(2) "it"
    [1]=>
    string(2) "in"
    [2]=>
    string(2) "is"
    [3]=>
    string(9) "intention"
    [4]=>
    string(9) "improving"
    [5]=>
    string(9) "instantly"
  }
  ["b"]=>
  array(6) {
    [0]=>
    string(5) "burst"
    [1]=>
    string(4) "both"
    [2]=>
    string(3) "bed"
    [3]=>
    string(3) "but"
    [4]=>
    string(6) "branch"
    [5]=>
    string(6) "become"
  }
  ["s"]=>
  array(6) {
    [0]=>
    string(5) "songs"
    [1]=>
    string(5) "sorry"
    [2]=>
    string(2) "so"
    [3]=>
    string(9) "strangers"
    [4]=>
    string(4) "such"
    [5]=>
    string(4) "sang"
  }
  ["e"]=>
  array(4) {
    [0]=>
    string(5) "equal"
    [1]=>
    string(6) "either"
    [2]=>
    string(3) "eat"
    [3]=>
    string(6) "except"
  }
  ["c"]=>
  array(3) {
    [0]=>
    string(5) "charm"
    [1]=>
    string(9) "contented"
    [2]=>
    string(7) "colonel"
  }
  ["j"]=>
  array(1) {
    [0]=>
    string(3) "joy"
  }
  ["h"]=>
  array(4) {
    [0]=>
    string(3) "her"
    [1]=>
    string(3) "ham"
    [2]=>
    string(9) "happiness"
    [3]=>
    string(2) "he"
  }
  ["t"]=>
  array(2) {
    [0]=>
    string(5) "those"
    [1]=>
    string(4) "they"
  }
  ["f"]=>
  array(3) {
    [0]=>
    string(5) "folly"
    [1]=>
    string(3) "fat"
    [2]=>
    string(7) "feeling"
  }
  ["n"]=>
  array(5) {
    [0]=>
    string(2) "no"
    [1]=>
    string(3) "new"
    [2]=>
    string(9) "northward"
    [3]=>
    string(6) "nearer"
    [4]=>
    string(3) "now"
  }
  ["r"]=>
  array(4) {
    [0]=>
    string(9) "recommend"
    [1]=>
    string(9) "resources"
    [2]=>
    string(6) "really"
    [3]=>
    string(6) "regret"
  }
  ["p"]=>
  array(2) {
    [0]=>
    string(9) "performed"
    [1]=>
    string(4) "past"
  }
  ["o"]=>
  array(3) {
    [0]=>
    string(2) "of"
    [1]=>
    string(6) "oppose"
    [2]=>
    string(3) "own"
  }
  ["l"]=>
  array(1) {
    [0]=>
    string(6) "length"
  }
  ["g"]=>
  array(3) {
    [0]=>
    string(6) "garden"
    [1]=>
    string(3) "get"
    [2]=>
    string(7) "garrets"
  }
  ["w"]=>
  array(4) {
    [0]=>
    string(6) "wishes"
    [1]=>
    string(2) "we"
    [2]=>
    string(4) "walk"
    [3]=>
    string(4) "want"
  }
}
stderr
PHP Notice:  Undefined variable: combined in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: a in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: d in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: i in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: b in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: s in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: e in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: c in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: j in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: h in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: t in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: f in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: n in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: r in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: p in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: o in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: l in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: g in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17
PHP Notice:  Undefined index: w in /home/Y1BEf2/prog.php on line 17
PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/Y1BEf2/prog.php on line 17