Skip to content

Instantly share code, notes, and snippets.

@krmgns
Last active March 15, 2021 11:50
Show Gist options
  • Save krmgns/ca98b47f6d4289eab7d9a99430381b92 to your computer and use it in GitHub Desktop.
Save krmgns/ca98b47f6d4289eab7d9a99430381b92 to your computer and use it in GitHub Desktop.
intdiv samples & polyfill.
<?php
// https://github.com/itchyny/gojq#difference-to-jq
$intdiv = fn($x, $y) => ($x - $x % $y) / $y;
// polyfill
if (!function_exists('intdiv')) {
function intdiv($x, $y) {
return ($x - $x % $y) / $y;
}
}
$x = 10; $y = 3;
var_dump($x / $y);
var_dump($x / $y | 0);
var_dump(intdiv($x, $y));
var_dump($intdiv($x, $y));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment