Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 17, 2020 16:33
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/d23d3eaaaa2330fb70ca0f292e57c703 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/d23d3eaaaa2330fb70ca0f292e57c703 to your computer and use it in GitHub Desktop.
Just PHP FUN 052.
<?php
# https://www.codewars.com/kata/581a52d305fe7756720002eb PHP in Action #1 - Introduction to Superglobals [Fundamentals].
function double_global_num() {
return $GLOBALS['num'] *= 2;
}
function set_query($query) {
return $_GET['query'] = $query;
}
function set_email($email) {
return $_POST['email'] = $email;
}

Just PHP FUN 052.

Started at 22:28 17.07.2020 Friday July.
Finished at 23:33 17.07.2020 Friday July. (1hr 05minutes)

<?php
# https://www.codewars.com/kata/57dbd9d68d7f5a785f00000f PHP Functions - The "Use" Keyword.
function multiple_closures($a){
return function($b,$c) use ($a){
return function ($d,$e) use ($a,$b,$c){
return $a + $b * $c - $d/$e;
};
};
}
<?php
# https://www.codewars.com/kata/581a52d305fe7756720002eb Is that a real phone number? (British version).
function validateNumber($str){
$s = str_replace('-','',$str);
if(preg_match('/^(\+44|0)7[0-9]{9}$/',$s)) return 'In with a chance';
return 'Plenty more fish in the sea';
}
<?php
# https://www.codewars.com/kata/58b63cb2b7d86adb650000b7 Simple Fun #173: A Hero Go To The School.
function which_bus_to_take(array $buses_colors, array $going_to_school): int {
$x = array_map(null, $buses_colors, $going_to_school);
$red = null; $blue = null;
foreach($x as $k => $v){
if( is_null($red) && $v[1] && 'red' == $v[0] ) {$red = $k;}
if( is_null($blue) && $v[1] && 'blue' == $v[0]) $blue = $k;
}
if(!is_null($red)) return $red;
return $blue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment