Replacing part of a string with another string is straight forward, but what if you have to replace last occurrence of a character or string with another string.
When working with CSS, it is common to use Hexadecimal Notation of colors, while on the back end, many PHP functions (like
imagecolorexact() etc, require that you pass on colors as red, green and blue integers.
PHP’s bitwise operators
>> 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.
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.