May 2025posted on 05.08.2025Today I Learned: PHP I had the opportunity to work on some PHP this week and picked up a few new tricks that are very different from JavaScript: Computing the difference in arrays $array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("b" => "green", "yellow", "red"); $result = array_diff($array1, $array2); Computing the intersection of arrays $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $result = array_intersect($array1, $array2); Inherit a variable inside an anonymous function $message = 'world'; $example = function () use ($message) { return "hello $message"; }; Reference a private function as a callback class MyClass { public static function getDifference() { $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $result = array_udiff($array1, $array2, array($this, 'filterById')); } private function filterById($a, $b) {} } Reference static members of a class using self class MyClass { public static $url = "https://petermekhaeil.com/"; public static function getUrl() { return self::$url; } } No reactions yet
Today I Learned: PHP
I had the opportunity to work on some PHP this week and picked up a few new tricks that are very different from JavaScript:
Computing the difference in arrays
Computing the intersection of arrays
Inherit a variable inside an anonymous function
Reference a private function as a callback
Reference static members of a class using
self