Archive for the 'Functions' Category

How would you like to be able to record hundreds, or thousands of different yes/no values in a single number? This is just one of the many applications where base_convert can come in handy.
Remember basic math classes in high school, where you learned about binary numbers, and hexadecimal, and other number systems that use a [...]


Sometimes you simply want to replace part of string with something else, like changing your address when you move. You could use a fancy grep replace or similar functionality, but if it is a simple substitution it is usually easier to just go with the string function str_replace.
Here is how it works:
$newwork = str_replace($old, $new, [...]


Sometimes you write a function in PHP that needs to know where in the directory hierarchy the code is being called from, to correctly access other files, such as those to be read, written or included. If the same function appears throughout your site, you can’t ‘hard code’ the location, because it changes from one [...]


The switch() function lets you choose between several options, depending on the value some variable takes. It is similar, for those of you who have programmed in Visual Basic, to the select case command in that language.
So, let’s say you have a feedback form with a drop-down list of typical reasons someone might have for [...]


Sometimes you have an array of elements that may contain duplicate entries, but you do want any duplication. Randomly selected elements are a good example of this. If you add elements to an array one at a time using the random function, it can return the same value more than once.
Removing any duplicates is easy [...]