PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $tests = [ '' => [], 'one' => ['one'], 'one and two' => ['one', 'two'], 'one, two and three' => ['one', 'two', 'three'], 'one, two, three and four' => ['one', 'two', 'three', 'four'], 'one, two, three, four and five' => ['one', 'two', 'three', 'four', 'five'], ]; function laravelJoin(array $words, string $separator = ', ', string $conjunction = ' and '): string { return collect($words)->join($separator, $conjunction); } printf("| %20s| 0️⃣ | 1️⃣ | 2️⃣ | 3️⃣ | 4️⃣ | 5️⃣ |\n", 'user \ elements'); $funcs = [ 'laravelJoin', ]; foreach ($funcs as $func) { echo "--------------------------------------------------------------------\n"; printf( "| %20s| %s | %s | %s | %s | %s | %s |\n", $func, ...array_map( fn($result, $expected) => $result === $expected ? '✅': '💩', array_map($func, $tests), array_keys($tests) ) ); } var_export(array_values(array_map($func, $tests)));
Show:  
Copy Clear