PHP Function: Built-in Functions part 2

Welcome back to part 2 of Built-In functions, just a reminder.

count()
The count() function counts the number of elements in a variable. It’s usually used to count the number of elements in an array, because any variable that is not an array has only one element – itself.

In the following example, $a  is assigned a value equal to the number of elements in the $colors array:

each() and list()
The each() and list() functions usually appear together, in the context of stepping through an array and returning its keys and values. Here is the syntax for these functions.

For example, when you submit an HTML form via the GET method, each key/value pair is placed in a global variable $HTTP_GET_VARS. If your form input fields are named first_name and last_name and the user enters values Joe and Smith, the key/value pairs are first_name/Joe and last_name/Smith. In the $HTTP_GET_VARS array, these variables are represented as the following:

You can use the each() and list() functions to step through the array in this fashion, printing the key and value for each element in the array:

reset()
The reset() function rewinds the pointer to the beginning of the array. Its syntax is
reset($array_name);

shuffle()
The shuffle() function randomizes the elements of a given array. Its syntax is
shuffle($array_name);

sizeof()
The sizeof() function counts the number of elements in an array. In the following example, $a is assigned a value equal to the number of elements in the $colors array

That’s if for this issue of Built-in functions kiddies. Next php function: Built-in Functions part 3