Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 18, 2020 16:26
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/4be7f622b4031b72427885c1f8525fc4 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/4be7f622b4031b72427885c1f8525fc4 to your computer and use it in GitHub Desktop.
Just PHP FUN 053.
<?php
# https://www.codewars.com/kata/5885b5d2b632089dc30000cc #~For Kids~# d/m/Y -> Day of the week.
function day_of_the_week($date){
return DateTime::createFromFormat("d/m/Y",$date)->format("l");
}

Just PHP FUN 053.

Started at 22:20 at 18.07.2020 Saturday July.
Finished at 23:26 at 18.07.2020 Saturday July. (1hr 06minutes)

<?php
# https://www.codewars.com/kata/58ac59d21c9e1d7dc5000150 Cut array into smaller parts.
function makeParts($arr,$chunkSize){
$ans = [];
$tmp = [];
foreach($arr as $v){
if(count($tmp) < $chunkSize){
array_push($tmp,$v);
}else{
array_push($ans,$tmp);
$tmp = [$v];
}
}
if(!empty($tmp)) array_push($ans,$tmp);
return $ans;
}
<?php
# https://www.codewars.com/kata/581e1d083a4820eb4f00004f MOD 256 without the MOD operator.
function mod256WithoutMod($number)
{
if($number > 0){
while($number >= 256) $number -= 256;
return $number;
}else{
while($number <= -256 ) $number += 256;
return $number;
}
}
<?php
# https://www.codewars.com/kata/57d41c425dc38eefbc0001cf PHP Functions - Anonymous Functions (aka Closures).
$hello_world = function(){ return 'Hello World';};
$person_description = function($x,$y,$z){return "$x is $y years old and currently works as a(n) $z";};
<?php
# https://www.codewars.com/kata/57d6ae421a6282aa4f000b97 PHP Functions - Type Declarations.
function multiply(int $a, int $b){ return $a*$b;}
function get_profile(Person $u){
list($n,$a,$g,$o) = [$u->name,$u->age,$u->gender,$u->occupation];
return "Name: $n\nAge: $a\nGender: $g\nOccupation: $o";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment