This function was inspired from PHP’s built-in function trim() that removes undesired characters from the start and end of a string, and in case no such characters are provided as second argument to the function, it removes white-space characters from both ends of the string.

Continue reading

PHP’s bitwise operators << and >> implement Arithmetic Bit Shifting. This means:

  • Left shift (using << operator) fills in zero(s) on the right end of the bitfield, and bit(s) shifted off the left end are discarded;
  • Right shift (using >> operator) discards bit(s) shifted off the right end of the bitfield and copy(ies) of sign bit are shifted in on the left end.

Logical Bit Shifting is different in that on right shifts, zeros are shifted in on the left end of the bitfield, affecting the sign of negative integer.

Continue reading

PHP does not provide any mathematical function like is_even to help you check if a given integer is an Even number or Odd. Writing your own such function is not difficult and below are listed a number of alternatives that provide different logical solutions to do this.

Continue reading