fork download
  1. <?php
  2.  
  3. $str = "mary had a little lamb and she loved it so";
  4.  
  5. $pieces = explode(" ", $str);
  6. $array = [];
  7.  
  8. foreach($pieces as $piece){
  9. //echo $piece;
  10.  
  11. for($i = 0; $i < count($piece); $i++){
  12.  
  13. $letter = strtoupper($piece[0]);
  14.  
  15. $newLetter = substr_replace($piece, $letter, 0, 1);
  16.  
  17. array_push($array, $newLetter);
  18. }
  19. }
  20. $result = implode(" ", $array);
  21. echo $result;
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Mary Had A Little Lamb And She Loved It So