This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Given a square matrix, calculate the absolute difference between the sums of its diagonals. | |
| * | |
| * @param array $matrix | |
| * @return integer | |
| */ | |
| function diagonal_difference(array $matrix) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Pipeline | |
| { | |
| /** | |
| * Executes a pipeline of functions. | |
| * | |
| * @return void | |
| */ | |
| public static function makePipeline() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function parseCsv( string $csv, string $delimiter) | |
| { | |
| return str_getcsv($csv, $delimiter); | |
| } | |
| $csv = 'a,b,c,"d,e",f,g'; | |
| $parsedArray = parseCsv($csv, ','); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $haystack = 'abcdefghijklmnopqrstuvwxy'; | |
| $needles = array('z', 'g', 'a', 'r'); | |
| array_walk($needles, function($needle) use ($haystack) { | |
| print strpos($haystack, $needle) !== FALSE ? "'{$needle}' exist in haystack" : "'{$needle}' does not exist"; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Palindrome | |
| { | |
| /** | |
| * Validates is a word is a palindrome. | |
| * | |
| * @param [type] $word | |
| * @return boolean | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function sortByPriceAscending(string $jsonString) : string | |
| { | |
| $items = json_decode($jsonString); | |
| usort($items, function($a, $b) | |
| { | |
| $cmp = $a->price - $b->price; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class CategoryTree | |
| { | |
| /** @var array $categoryTree */ | |
| private $categoryTree = []; | |
| /** | |
| * Adds new root category or creates a parent-child relationship. | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $files = [ | |
| 'blah.gif', | |
| 'my.file.gif', | |
| 'my.file.jpg', | |
| 'this/is/a/path', | |
| 'my.file.xlsx', | |
| 'this/is/a/path', | |
| 'my.file.php', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class First {} | |
| class Second {} | |
| class Third extends Second {} | |
| class Fourth {} | |
| $userClasses = array_filter( | |
| get_declared_classes(), | |
| function($className) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class First {} | |
| class Second {} | |
| class Third extends Second {} | |
| class Fourth {} | |
| $userClasses = array_filter( | |
| get_declared_classes(), | |
| function($className) { |