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 | |
$original = $elements = [ | |
'A' => 100, | |
'B' => 80, | |
'C' => 60, | |
'D' => 5, | |
]; | |
function chooseElementFromWeightedList(array $list) |
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
Search: \/\*{3,}(\n(?:\s\*[^\*]*\n)+\s)\*{3,}\/ | |
Replace: /*$1*/ |
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 | |
$functions = [ | |
'array_flip & isset' => function (array $haystack, array $needles) { | |
$haystackFlip = array_flip($haystack); | |
foreach ($needles as $key => $needle) { | |
if (!isset($haystackFlip[$needle])) { | |
unset($needles[$key]); | |
} | |
} |
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 | |
define('FILTER_MATCH_EXACT', 1 << 0); | |
define('FILTER_MATCH_LOOSE', 1 << 1); | |
define('FILTER_INVERT', 1 << 2); | |
function filter(mixed $specimen, int $flags = FILTER_MATCH_EXACT): Closure | |
{ | |
// Unset FILTER_MATCH_EXACT if FILTER_MATCH_LOOSE is set. | |
if ($flags & FILTER_MATCH_LOOSE) { |
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 Cache | |
{ | |
public function has(string $id): bool | |
{ | |
} | |
public function get(string $id): array | |
{ |
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 | |
// Library Code | |
class Browser | |
{ | |
public function createPage(): Page | |
{ | |
return new Page(); | |
} | |
} |
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 | |
declare(strict_types=1); | |
function assertConstantOfClass(string $class, $constantValue): void | |
{ | |
$reflection = new ReflectionClass($class); | |
$constants = $reflection->getConstants(); | |
foreach ($constants as $value) { | |
if ($value === $constantValue) { |
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 Magic | |
{ | |
public function add() | |
{ | |
$args = func_get_args(); | |
$count = count($args); | |
$methods = []; |
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 | |
$functions = [ | |
'usort (from stackoverflow)' => function (array $input, array $order): array { | |
usort( | |
$input, | |
function ($a, $b) use ($order) { | |
$pos_a = array_search($a['id'], $order); | |
$pos_b = array_search($b['id'], $order); | |
return $pos_a - $pos_b; |
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 | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Helper\ProgressBar; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\ConsoleOutput; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use TYPO3\CMS\Core\Database\ConnectionPool; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; |