Blog

Passing Values By Reference In PHP

Saturday, February 16, 2008 - 15:33

For most functions it is normal for have the function return the output of a calculation. With PHP it is also possible to pass values to the function by reference. A better way of saying this is rather than pass the value of the variable you pass a pointer to the variable itself. When you do this anything that you do to the variable inside the function is also done outside, so if you interact with the variable again it will contain a different value.

Category: 

Custom Error Handling In PHP Using set_error_handler()

Wednesday, February 13, 2008 - 13:27

The set_error_handler() function can be used in PHP to allow you to catch any run time errors and act accordingly. This function can take two parameters:

  • Error Handler : This a string which is the name of the function that will be called if an error is encountered.
  • Error Types (optional) : This is an optional parameter used to tell PHP on what error codes to act. This is the same error reporting setting.

The function that is defined in the function must have the following footprint as a minimum.

Category: 

Append One Array To Another In PHP

Tuesday, February 12, 2008 - 22:01

Appending arrays in PHP can be done with the array_merge() function. The array will take any number of arrays as arguments and will return a single array. Here is an example using just two arrays.

Category: 

PHP Random Quote Generator

Monday, February 11, 2008 - 20:28

The following code loads the contents of a text file and randomly displays a line from it. You can use this to display a random quote on a page every time it loads.

Category: