Browsing category PHP

Working with Timezones in PHP

It is very important to pay attention to time zones in PHP. Your server might be hosted in one location while your visitors might be in another time zone. The local time of your visitors will be different from your server’s. To handle such differences, there are several inbuilt PHP functions. These functions allow you

PHP time and Other Related Functions

In PHP, the time() function is used to display the current Unix timestamp in milliseconds. Of course, a whole lot more can be achieved with this and other related functions. You can use the time function to find out the unix timestamp. This can later be formatted using the date() function. Example:


Date and Time in PHP

If you need to work with date and time in PHP, you can use the date() function. It will output the date as well as time in your desired format. There are several formatting options. You can choose among them to decide how the date is displayed. A simple example use of date() function is:

Die, Exit and Break in PHP

Die and Exit These two constructs are equivalent with each other. They are used to stop the execution of the current PHP script. A message can also be printed as well. These are used when there is an error in a script and you want to exit it as soon as a problem is encountered.

Advanced Variables and Using Them by Reference in PHP

Variables by Reference Variables can also hold their value as a reference to another value. This means, a variable simply points to another variable. So whatever value the other variable holds, the reference variable also holds the same. For reference assignment we use an ampersand sign (&) after the equals to sign (=) while assigning

Using List in PHP to Access Array Values to Multi Dimensions

If you are looking to assign the values of an array to a group of variables with one statement, use list(). This construct is used to give a list of variables some value. They work only with arrays that use numeric indexes. Example:

You can also use list to pick individual values while

Cycling Through PHP Arrays using Pointers

Cycling Through PHP Arrays When accessing the values of PHP arrays, looping them through foreach loops is not the only way. We can get individual values and keys of an array. There are invisible pointers in an array that tells the current position. We can cycle through them to get values at different positions of