3v4l.org

run code in 300+ PHP versions simultaneously
<?php function wp_total_pages( $total_items, $per_page ) { $remainder = $total_items % $per_page; if ( $remainder ) { $total_items += $per_page - $remainder; } return $total_items / $per_page; } $input_sets = [ [506, 10], [505, 10], [504, 10], [500, 9.5], [500, 9], [35478743512, 15], [PHP_INT_MAX, 20], [PHP_INT_MAX + 250, 20], ]; foreach ($input_sets as list($a, $b)) { echo PHP_EOL, '=================================================', PHP_EOL; echo 'Given the following inputs:', PHP_EOL; var_dump($a, $b); $over = $a % $b; $over = ($over > 0) ? 1 : 0; echo PHP_EOL, 'The results will be:', PHP_EOL; echo 'ceil: ', var_dump(ceil($a/$b)); echo 'round + ceil: ', var_dump(round(ceil($a/$b))); echo 'wp_total_pages: ', var_dump(wp_total_pages($a, $b)); try { if (function_exists('intdiv')) { echo 'intdiv: ', var_dump($over + intdiv($a, $b)); } else { echo 'intdiv function not available', PHP_EOL; } } catch (Error $e) { echo 'intdiv: ', $e->getMessage(), PHP_EOL; } try { echo 'bcdiv: ', var_dump($over + bcdiv($a, $b)); } catch (Error $e) { echo 'bcdiv: ', $e->getMessage(), PHP_EOL; } echo PHP_EOL, 'And the results with an int cast added will be:', PHP_EOL; echo 'ceil: ', var_dump((int) ceil($a/$b)); echo 'round + ceil: ', var_dump((int) round(ceil($a/$b))); echo 'wp_total_pages: ', var_dump((int) wp_total_pages($a, $b)); try { if (function_exists('intdiv')) { echo 'intdiv: ', var_dump((int)($over + intdiv($a, $b))); } else { echo 'intdiv function not available', PHP_EOL; } } catch (Error $e) { echo 'intdiv: ', $e->getMessage(), PHP_EOL; } try { echo 'bcdiv: ', var_dump((int) ($over + bcdiv($a, $b))); } catch (Error $e) { echo 'bcdiv: ', $e->getMessage(), PHP_EOL; } }
Output for git.master, git.master_jit, rfc.property-hooks
================================================= Given the following inputs: int(506) int(10) The results will be: ceil: float(51) round + ceil: float(51) wp_total_pages: int(51) intdiv: int(51) bcdiv: int(51) And the results with an int cast added will be: ceil: int(51) round + ceil: int(51) wp_total_pages: int(51) intdiv: int(51) bcdiv: int(51) ================================================= Given the following inputs: int(505) int(10) The results will be: ceil: float(51) round + ceil: float(51) wp_total_pages: int(51) intdiv: int(51) bcdiv: int(51) And the results with an int cast added will be: ceil: int(51) round + ceil: int(51) wp_total_pages: int(51) intdiv: int(51) bcdiv: int(51) ================================================= Given the following inputs: int(504) int(10) The results will be: ceil: float(51) round + ceil: float(51) wp_total_pages: int(51) intdiv: int(51) bcdiv: int(51) And the results with an int cast added will be: ceil: int(51) round + ceil: int(51) wp_total_pages: int(51) intdiv: int(51) bcdiv: int(51) ================================================= Given the following inputs: int(500) float(9.5) Deprecated: Implicit conversion from float 9.5 to int loses precision in /in/V6jdD on line 26 The results will be: ceil: float(53) round + ceil: float(53) wp_total_pages: Deprecated: Implicit conversion from float 9.5 to int loses precision in /in/V6jdD on line 4 float(53.10526315789474) intdiv: Deprecated: Implicit conversion from float 9.5 to int loses precision in /in/V6jdD on line 35 int(56) bcdiv: int(53) And the results with an int cast added will be: ceil: int(53) round + ceil: int(53) wp_total_pages: Deprecated: Implicit conversion from float 9.5 to int loses precision in /in/V6jdD on line 4 int(53) intdiv: Deprecated: Implicit conversion from float 9.5 to int loses precision in /in/V6jdD on line 54 int(56) bcdiv: int(53) ================================================= Given the following inputs: int(500) int(9) The results will be: ceil: float(56) round + ceil: float(56) wp_total_pages: int(56) intdiv: int(56) bcdiv: int(56) And the results with an int cast added will be: ceil: int(56) round + ceil: int(56) wp_total_pages: int(56) intdiv: int(56) bcdiv: int(56) ================================================= Given the following inputs: int(35478743512) int(15) The results will be: ceil: float(2365249568) round + ceil: float(2365249568) wp_total_pages: int(2365249568) intdiv: int(2365249568) bcdiv: int(2365249568) And the results with an int cast added will be: ceil: int(2365249568) round + ceil: int(2365249568) wp_total_pages: int(2365249568) intdiv: int(2365249568) bcdiv: int(2365249568) ================================================= Given the following inputs: int(9223372036854775807) int(20) The results will be: ceil: float(4.611686018427388E+17) round + ceil: float(4.611686018427388E+17) wp_total_pages: float(4.611686018427388E+17) intdiv: int(461168601842738791) bcdiv: int(461168601842738791) And the results with an int cast added will be: ceil: int(461168601842738816) round + ceil: int(461168601842738816) wp_total_pages: int(461168601842738816) intdiv: int(461168601842738791) bcdiv: int(461168601842738791) ================================================= Given the following inputs: float(9.223372036854776E+18) int(20) Deprecated: Implicit conversion from float 9.223372036854776E+18 to int loses precision in /in/V6jdD on line 26 The results will be: ceil: float(4.611686018427388E+17) round + ceil: float(4.611686018427388E+17) wp_total_pages: Deprecated: Implicit conversion from float 9.223372036854776E+18 to int loses precision in /in/V6jdD on line 4 float(4.611686018427388E+17) intdiv: intdiv: intdiv(): Argument #1 ($num1) must be of type int, float given bcdiv: bcdiv: bcdiv(): Argument #1 ($num1) is not well-formed And the results with an int cast added will be: ceil: int(461168601842738816) round + ceil: int(461168601842738816) wp_total_pages: Deprecated: Implicit conversion from float 9.223372036854776E+18 to int loses precision in /in/V6jdD on line 4 int(461168601842738816) intdiv: intdiv: intdiv(): Argument #1 ($num1) must be of type int, float given bcdiv: bcdiv: bcdiv(): Argument #1 ($num1) is not well-formed

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
69.18 ms | 413 KiB | 8 Q