Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 24, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/38057d1f3e95b871d90f2d497d3d730d to your computer and use it in GitHub Desktop.
Save lbvf50mobile/38057d1f3e95b871d90f2d497d3d730d to your computer and use it in GitHub Desktop.
Just PHP FUN 111.
<?php
# https://www.codewars.com/kata/5266876b8f4bf2da9b000362 Who likes it?
function likes( $names ) {
$size = count($names);
if(0 == $size) return "no one likes this";
if(1 == $size) return sprintf("%s likes this",$names[0]);
if(2 == $size) return sprintf("%s and %s like this",$names[0],$names[1]);
if(3 == $size) return sprintf("%s, %s and %s like this",$names[0],$names[1],$names[2]);
return sprintf("%s, %s and %s others like this",$names[0],$names[1],$size-2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment