Skip to content

Instantly share code, notes, and snippets.

View fabiocicerchia's full-sized avatar
🏠
Working from home

Fabio Cicerchia fabiocicerchia

🏠
Working from home
View GitHub Profile
@fabiocicerchia
fabiocicerchia / TheUnexpectedFizzBuzz.php
Last active March 10, 2020 13:54 — forked from gfabrizi/TheUnexpectedFizzBuzz.php
A different (...veeeery different) approach to the good old PHP FizzBuzz test
#!/usr/bin/env php
<?php
if ($argc !== 2 || !ctype_digit($argv[1]))
die('You must specifiy only one parameter: the max number as an integer' . PHP_EOL);
for ($input = (int) $argv[1], $i = 0; $i < $input; ) echo ([
0 => 'FizzBuzz',
3 => 'Fizz', 6 => 'Fizz', 9 => 'Fizz', 12 => 'Fizz',
5 => 'Buzz', 10 => 'Buzz',
@fabiocicerchia
fabiocicerchia / combos.php
Last active May 1, 2024 22:02 — forked from farinspace/combos.php
PHP - Generate all the possible combinations among a set of nested arrays.
/**
* Generate all the possible combinations among a set of nested arrays.
*
* @param array $data The entrypoint array container.
* @param array $all The final container (used internally).
* @param array $group The sub container (used internally).
* @param mixed $val The value to append (used internally).
* @param int $i The key index (used internally).
*/
function generate_combinations(array $data, array &$all = array(), array $group = array(), $value = null, $i = 0)
<?php
function safe_truncate_text($text, $lenght)
{
$trailingDots = '';
$truncatedText = substr($text . ' ', 0, $lenght);
if (strlen($text) > $lenght)
{
$truncatedText = preg_replace('/ [^ ]+$/', '', ' ' . $truncatedText);