PHP Linked List with end and start List Node pointers

<?php class ListNode { public $data = NULL; public $next = NULL; function __construct(string $data = NULL) { $this->data = $data; } } class LinkedList { private $_firstNode = NULL; private $_lastNode = NULL; private $_totalNodes = 0; function insert(string $data =...

PHP float number not add up

Why my numbers are not equal PHP? Floating point precision Floating point numbers have limited precision. Although it depends on the system, PHP typically uses the IEEE 754 double precision format, which will give a maximum relative error due to rounding in the order...

Division in PHP

Do we still need intdiv() since PHP 8.0 / operator supports error throwing when dividing by 0? intdiv(10, 3) == 3;intdiv(-10, 3) == -3; (int)(10 / 3) == 3;(int)(-10 / 3) == -3; floor(10/3) == 3;floor(-10/3) == -4; <?php $start1 = microtime(true); $i = 1; while ($i...

PHP division by 0

Divide by 0 in PHP How the division by 0 behave in PHP8, PHP7, PHP5 PHP has evolved in the last few years. Before when dividing by 0 we only get a warning. This behaviour did not change until php8, where numeric division 10 / 0 resulted in rasing an Error...

PHP one directional linked list

To create a list, we need to declare two classes, List Node and Linked List classes. Basic PHP one directional linked list PHP Linked list and its methods <?php class ListNode { public $data = NULL; public $next = NULL; function __construct(string $data = NULL) {...

Overriding and overloading methods in PHP

Overriding methods in PHP Overriding and overloading messages in PHP can be a little weird! There are things that will work ant stuff which will not. For example, this method overriding will work: <?php class A { function test(string $s) { echo “$s”; }...