PHP - tutorial - 08 - arrays

revision:


An array stores multiple values in one single variable.

In PHP, the "array() function" is used to create an array.

There are three types of arrays: 1/indexed arrays - arrays with a numeric index; 2/ associative arrays - arrays with named keys; 3/ multidimensional arrays - arrays containing one or more arrays.

example:

I like Volvo, BMW and Toyota.
code:
                <?php
                    $cars = array("Volvo", "BMW", "Toyota"); 
                    echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
                ?>
            

The count() function is used to return the length (the number of elements) of an array.

example:

4
code:
                <?php
                    $cars = array("Volvo", "Mercedes", "Tesla", "Toyota");
                    echo count($cars);
                ?>
            

There are two ways to create indexed arrays:

The index can be assigned automatically (index always starts at 0), like this : $cars = array("Volvo", "BMW", "Toyota");
or the index can be assigned manually : $cars[0] = "Volvo"; $cars[1] = "BMW"; $cars[2] = "Toyota";

example:

I like Bentley, Porsche and Chrysler.
code:
                <?php
                    $cars = array("Bentley", "Porsche", "Chrysler"); 
                    echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
                ?>
            

To loop through and print all the values of an indexed array, you could use a for loop.

example:

Tesla
Benz
Hyundai
code:
                <?php
                    $cars = array("Tesla", "Benz", "Hyundai");
                    $arrlength = count($cars);
                    
                    for($x = 0; $x < $arrlength; $x++) {
                    echo $cars[$x];
                    echo "<br>";
                    }
                ?>
            

Associative arrays are arrays that use named keys that you assign to them.

There are two ways to create an associative array:

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
or:
$age['Peter'] = "35"; $age['Ben'] = "37"; $age['Joe'] = "43";
The named keys can then be used in a script.

example:

Peter is 35 years old.
code:
                <?php
                    $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
                    echo "Peter is " . $age['Peter'] . " years old.";
               ?>
            

To loop through and print all the values of an associative array, you could use a foreach loop.

example:

Key=Theo, Value=35
Key=Johan, Value=37
Key=Esther, Value=43
code:
                <?php
                    $age = array("Theo"=>"35", "Johan"=>"37", "Esther"=>"43");
                    foreach($age as $x => $x_value) {
                        echo "Key=" . $x . ", Value=" . $x_value;
                        echo "<br>";
                    }  
                ?>
            

A multidimensional array is an array containing one or more arrays.

The dimension of an array indicates the number of indices you need to select an element. For a two-dimensional array you need two indices to select an element; for a three-dimensional array you need three indices to select an element.

example:

Volvo: in stock: 22, sold: 18.
BMW: in stock: 15, sold: 13.
Saab: in stock: 5, sold: 2.
Land Rover: in stock: 17, sold: 15.
code:
                <?php
                    $cars = array (
                        array("Volvo",22,18),
                        array("BMW",15,13),
                        array("Saab",5,2),
                        array("Land Rover",17,15)
                    );
                        
                    echo $cars[0][0].": in stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
                    echo $cars[1][0].": in stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
                    echo $cars[2][0].": in stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
                    echo $cars[3][0].": in stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
                ?>
                
            

We can also put a for loop inside another for loop to get the elements of the $cars array (we still have to point to the two indices).

example:

Row number 0

Row number 1

Row number 2

Row number 3

code:
                <?php
                    $cars = array (
                        array("Volvo",22,18),
                        array("BMW",15,13),
                        array("Saab",5,2),
                        array("Land Rover",17,15)
                    );
                        
                    for ($row = 0; $row < 4; $row++) {
                        echo "<p><b>Row number $row</b></p>";
                        echo "<ul>";
                        for ($col = 0; $col < 3; $col++) {
                        echo "<li>".$cars[$row][$col]."</li>";
                        }
                        echo "</ul>";
                    } 
                ?>
            

The elements in an array can be sorted.

Sorting can be done in alphabetical or numerical order, descending or ascending.

PHP has following sort functions for arrays:

sort() - sort arrays in ascending order;
rsort() - sort arrays in descending order;
asort() - sort associative arrays in ascending order, according to the value;
ksort() - sort associative arrays in ascending order, according to the key;
arsort() - sort associative arrays in descending order, according to the value;
krsort() - sort associative arrays in descending order, according to the key.

example:

BMW
Benz
Tesla
Toyota
Volvo
code:
                <?php
                $cars = array("Volvo", "BMW", "Toyota", "Benz", "Tesla");
                    sort($cars);
                    
                    $clength = count($cars);
                    for($x = 0; $x < $clength; $x++) {
                    echo $cars[$x];
                    echo "<br>";
                    }
                ?>
            

example:

2
4
6
11
22
code:
                <?php
                    $numbers = array(4, 6, 2, 22, 11);
                    sort($numbers);

                    $arrlength = count($numbers);
                    for($x = 0; $x < $arrlength; $x++) {
                    echo $numbers[$x];
                    echo "<br>";
                    }
                ?>
            

example : different sortings

Volvo
Toyota
BMW

22
11
6
4
2

Key=Ben, Value=37
Key=Joe, Value=43
Key=Peter, Value=35

Key=Joe, Value=43
Key=Ben, Value=37
Key=Peter, Value=35
code:
                <?php
                    $cars = array("Volvo", "BMW", "Toyota");
                    rsort($cars);
                    
                    $clength = count($cars);
                    for($x = 0; $x < $clength; $x++) {
                        echo $cars[$x];
                        echo "<br>";
                    }
                    echo "<br>";
                    $numbers = array(4, 6, 2, 22, 11);
                    rsort($numbers);

                    $arrlength = count($numbers);
                    for($x = 0; $x < $arrlength; $x++) {
                        echo $numbers[$x];
                        echo "<br>";
                    }
                    echo "<br>";
                    $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
                    ksort($age);

                    foreach($age as $x => $x_value) {
                    echo "Key=" . $x . ", Value=" . $x_value;
                    echo "<br>";
                    }
                    echo "<br>";
                    arsort($age);
                    foreach($age as $x => $x_value) {
                        echo "Key=" . $x . ", Value=" . $x_value;
                        echo "<br>";
                    }
                ?>
            

PHP - array references

array(value1, value2, value3, etc.) or array(key=>value,key=>value,key=>value,etc.) - creates an array;

parameter values:

key : specifies the key (numeric or string)

value : specifies the value

array_change_key_case(array, case) - changes all keys in an array to lowercase or uppercase;

parameter values:

array : Required. Specifies the array to use.

case : Optional. Possible values:CASE_LOWER - Default value. Changes the keys to lowercase; CASE_UPPER - Changes the keys to uppercase

array_chunk(array, size, preserve_key) - splits an array into chunks of arrays;

parameter values:

array : Required. Specifies the array to use

size : Required. An integer that specifies the size of each chunk

preserve_key : Optional. Possible values: true - Preserves the keys; false - Default. Reindexes the chunk numerically

array_column(array, column_key, index_key) - returns the values from a single column in the input array;

parameter values:

array : Required. Specifies the multi-dimensional array (record-set) to use. As of PHP 7.0, this can also be an array of objects.

column_key : Required. An integer key or a string key name of the column of values to return. This parameter can also be NULL to return complete arrays (useful together with index_key to re-index the array)

index_key : Optional. The column to use as the index/keys for the returned array

array_combine(keys, values) - creates an array by using the elements from one "keys" array and one "values" array;

parameter values:

keys : Required. Array of keys

values : Required. Array of values

array_count_values(array) - counts all the values of an array;

parameter values:

array : Required. Specifying the array to count values of

array_diff(array1, array2, array3, ...) - compare arrays, and returns the differences (compare values only);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

array_diff_assoc(array1, array2, array3, ...) - compare arrays, and returns the differences (compare keys and values);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

array_diff_key(array1, array2, array3, ...) - compare arrays, and returns the differences (compare keys only);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

array_diff_uassoc(array1, array2, array3, ..., myfunction) - compare arrays, and returns the differences (compare keys and values, using a user-defined key comparison function);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunction :Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_diff_ukey(array1, array2, array3, ...,myfunction) - compare arrays, and returns the differences (compare keys only, using a user-defined key comparison function);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunction :Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_fill(index, number, value) - fills an array with values;

parameter values:

index : Required. The first index of the returned array

number : Required. Specifies the number of elements to insert

value : Required. Specifies the value to use for filling the array

array_fill_keys(keys, value) - fills an array with values, specifying keys;

parameter values:

keys : Required. Array of values that will be used as keys

value : Required. Specifies the value to use for filling the array

array_filter(array, callbackfunction, flag) - filters the values of an array using a callback function;

parameter values:

array : Required. Specifies the array to filter

callbackfunction : Optional. Specifies the callback function to use

flag : Optional. Specifies what arguments are sent to callback: ARRAY_FILTER_USE_KEY - pass key as the only argument to callback (instead of the value), ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to callback (instead of the value)

array_flip(array) - flips/exchanges all keys with their associated values in an array;

parameter values:

array : Required. Specifies an array of key/value pairs to be flipped

array_intersect(array1, array2, array3, ...) - compare arrays, and returns the matches (compare values only);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

array_intersect_assoc(array1,array2,array3, ...) - compare arrays and returns the matches (compare keys and values);

parameter values:

array1 : Required. The first array is the array that the others will be compared with

array2 : Required. An array to be compared with the first array

array3 : Optional. An array to be compared with the first array

array_intersect_key(array1, array2, array3, ...) - compare arrays, and returns the matches (compare keys only);

parameter values:

array1 : Required. The first array is the array that the others will be compared with

array2 : Required. An array to be compared with the first array

array3 : Optional. An array to be compared with the first array

array_intersect_uassoc(array1, array2, array3, ..., myfunction) - compare arrays, and returns the matches (compare keys and values, using a user-defined key comparison function);

parameter values:

array1 : Required. The first array is the array that the others will be compared with

array2 : Required. An array to be compared with the first array

array3 : Optional. An array to be compared with the first array

myfunction : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_intersect_ukey(array1, array2, array3, ..., myfunction) - compare arrays, and returns the matches (compare keys only, using a user-defined key comparison function);

parameter values:

array1 : Required. The first array is the array that the others will be compared with

array2 : Required. An array to be compared with the first array

array3 : Optional. An array to be compared with the first array

myfunction : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_key_exists(key, array) - checks if the specified key exists in the array;

parameter values:

key : Required. Specifies the key

array : Required. Specifies an array

array_keys(array, value, strict) - returns all the keys of an array;

parameter values:

array : Required. Specifies an array

value : Optional. You can specify a value, then only the keys with this value are returned

strict : Optional. Used with the value parameter. Possible values: true - Returns the keys with the specified value, depending on type: the number 5 is not the same as the string "5", false - Default value. Not depending on type, the number 5 is the same as the string "5".

array_map(myfunction, array1, array2, array3, ...) - sends each value of an array to a user-made function, which returns new values;

parameter values:

myfunction : Required. The name of the user-made function, or null

array1 : Required. Specifies an array

array2 : Optional. Specifies an array

array3 : Optional. Specifies an array

array_merge(array1, array2, array3, ...) - merges one or more arrays into one array;

parameter values:

array1 : Required. Specifies an array

array2 : Optional. Specifies an array

array3 : Optional. Specifies an array

array_merge_recursive(array1, array2, array3, ...) - merges one or more arrays into one array recursively;

parameter values:

array1 : Required. Specifies an array

array2 : Optional. Specifies an array

array3 : Optional. Specifies an array

array_multisort(array1, sortorder, sorttype, array2, array3, ...) - sorts multiple or multi-dimensional arrays;

parameter values:

array1 : Required. Specifies an array

sortorder : Optional. Specifies the sorting order. Possible values:SORT_ASC - Default. Sort in ascending order (A-Z);SORT_DESC - Sort in descending order (Z-A)

sorttype : Optional. Specifies the type to use, when comparing elements. Possible values:SORT_REGULAR - Default. Compare elements normally (Standard ASCII); SORT_NUMERIC - Compare elements as numeric values; SORT_STRING - Compare elements as string values; SORT_LOCALE_STRING - Compare elements as string, based on the current locale (can be changed using setlocale()); SORT_NATURAL - Compare elements as strings using "natural ordering" like natsort(); SORT_FLAG_CASE - Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

array2 : Optional. Specifies an array

array3 : Optional. Specifies an array

array_pad(array, size, value) - inserts a specified number of items, with a specified value, to an array;

parameter values:

array : Required. Specifies an array

size : Required. Specifies the number of elements in the array returned from the function

value : Required. Specifies the value of the new elements in the array returned from the function

array_pop(array) - deletes the last element of an array;

parameter values:

array : Required. Specifies an array

array_product(array) - calculates the product of the values in an array;

parameter values:

array : Required. Specifies an array

array_push(array, value1, value2, ...) - inserts one or more elements to the end of an array;

parameter values:

array : Required. Specifies an array

value1 : Optional. Specifies the value to add (Required in PHP versions before 7.3)

value2 : Optional. Specifies the value to add

array_rand(rray, number) - returns one or more random keys from an array;

parameter values:

array : Required. Specifies an array

number : Optional. Specifies how many random keys to return

array_reduce(array, myfunction, initial) - returns an array as a string, using a user-defined function;

parameter values:

array : Required. Specifies an array

myfunction : Required. Specifies the name of the function

initial : Optional. Specifies the initial value to send to the function

array_replace(array1, array2, array3, ...) - replaces the values of the first array with the values from following arrays;

parameter values:

array1 : Required. Specifies an array

array2 : Optional. Specifies an array which will replace the values of array1

array3 : Optional. Specifies more arrays to replace the values of array1 and array2, etc. Values from later arrays will overwrite the previous ones.

array_replace_recursive(array1, array2, array3, ...) - replaces the values of the first array with the values from following arrays recursively;

parameter values:

array1 : Required. Specifies an array

array2 : Optional. Specifies an array which will replace the values of array1

array3 : Optional. Specifies more arrays to replace the values of array1 and array2, etc. Values from later arrays will overwrite the previous ones.

array_reverse(rray, preserve) - returns an array in the reverse order;

parameter values:

array : Required. Specifies an array

preserve : Optional. Specifies if the function should preserve the keys of the array or not. Possible values: true, false.

array_search(value, array, strict) - searches an array for a given value and returns the key;

parameter values:

vale : Required. Specifies the value to search for

array : Required. Specifies the array to search in

strict : Optional. If this parameter is set to TRUE, then this function will search for identical elements in the array. Possible values: true, false - Default. When set to true, the number 5 is not the same as the string 5

array_shift(array) - removes the first element from an array, and returns the value of the removed element;

parameter values:

array : Required. Specifies an array

array_slice(array, start, length, preserve) - returns selected parts of an array;

parameter values:

array : Required. Specifies an array

start : Required. Numeric value. Specifies where the function will start the slice. 0 = the first element. If this value is set to a negative number, the function will start slicing that far from the last element. -2 means start at the second last element of the array.

length : Optional. Numeric value. Specifies the length of the returned array. If this value is set to a negative number, the function will stop slicing that far from the last element. If this value is not set, the function will return all elements, starting from the position set by the start-parameter.

preserve : Optional. Specifies if the function should preserve or reset the keys. Possible values: true - Preserve keys, false - Default. Reset keys

array_splice(array, start, length, array) - removes and replaces specified elements of an array;

parameter values:

array : Required. Specifies an array

start : Required. Numeric value. Specifies where the function will start removing elements. 0 = the first element. If this value is set to a negative number, the function will start that far from the last element. -2 means start at the second last element of the array.

length : Optional. Numeric value. Specifies how many elements will be removed, and also length of the returned array. If this value is set to a negative number, the function will stop that far from the last element. If this value is not set, the function will remove all elements, starting from the position set by the start-parameter.

array : Optional. Specifies an array with the elements that will be inserted to the original array. If it's only one element, it can be a string, and does not have to be an array.

array_sum(array) - returns the sum of the values in an array;

parameter values:

array : Required. Specifies an array

array_udiff(array1, array2, array3, ..., myfunction) - compare arrays, and returns the differences (compare values only, using a user-defined key comparison function);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunction : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_udiff_assoc(array1, array2, array3, ..., myfunction) - compare arrays, and returns the differences (compare keys and values, using a built-in function to compare the keys and a user-defined function to compare the values);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunction : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value) - compare arrays, and returns the differences (compare keys and values, using two user-defined key comparison functions);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunc_key : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

myfunc_value : Required. The name of the user-defined function that compares the array values. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

array_uintersect(array1, array2, array3, ..., myfunction) - compare arrays, and returns the matches (compare values only, using a user-defined key comparison function);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunction : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_uintersect_assoc(array1, array2, array3, ..., myfunction) - compare arrays, and returns the matches (compare keys and values, using a built-in function to compare the keys and a user-defined function to compare the values);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunction : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

array_uintersect_uassoc(rray1, array2, array3, ..., myfunc_key, myfunc_value) - compare arrays, and returns the matches (compare keys and values, using two user-defined key comparison functions);

parameter values:

array1 : Required. The array to compare from

array2 : Required. An array to compare against

array3 : Optional. More arrays to compare against

myfunc_key : Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

myfunc_value : Required. The name of the user-defined function that compares the array values. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

array_unique(array, sorttype) - removes duplicate values from an array;

parameter values:

array : Required. Specifying an array

sorttype : Optional. Specifies how to compare the array elements/items. Possible values:SORT_STRING - Default. Compare items as strings, SORT_REGULAR - Compare items normally (don't change types), SORT_NUMERIC - Compare items numerically, SORT_LOCALE_STRING - Compare items as strings, based on current locale

array_unshift(array, value1, value2, value3, ...) - adds one or more elements to the beginning of an array;

parameter values:

array : Required. Specifying an array

value1 : Optional. Specifies a value to insert (Required in PHP versions before 7.3)

value2 : Optional. Specifies a value to insert

value3 : Optional. Specifies a value to insert

array_values(array) - returns all the values of an array;

parameter values:

array : Required. Specifying an array

array_walk(array, myfunction, parameter...) - applies a user function to every member of an array;

parameter values:

array : Required. Specifying an array

myfunction : Required. The name of the user-defined function

parameter : Optional. Specifies a parameter to the user-defined function. You can assign one parameter to the function, or as many as you like

array_walk_recursive(array, myfunction, parameter...) - applies a user function recursively to every member of an array;

parameter values:

array : Required. Specifying an array

myfunction : Required. The name of the user-defined function

parameter : Optional. Specifies a parameter to the user-defined function. You can assign one parameter to the function, or as many as you like

arsort(array, sorttype) - sorts an associative array in descending order, according to the value;

parameter values:

array : Required. Specifies the array to sort

sorttype : Optional. Specifies how to compare the array elements/items. Possible values: 0 = SORT_REGULAR - Default. Compare items normally (don't change types), 1 = SORT_NUMERIC - Compare items numerically, 2 = SORT_STRING - Compare items as strings, 3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale, 4 = SORT_NATURAL - Compare items as strings using natural ordering, 5 = SORT_FLAG_CASE -

asort(array, sorttype) - sorts an associative array in ascending order, according to the value;

parameter values:

array : Required. Specifies the array to sort

sorttype : Optional. Specifies how to compare the array elements/items. Possible values: 0 = SORT_REGULAR - Default. Compare items normally (don't change types), 1 = SORT_NUMERIC - Compare items numerically, 2 = SORT_STRING - Compare items as strings, 3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale, 4 = SORT_NATURAL - Compare items as strings using natural ordering, 5 = SORT_FLAG_CASE -

compact(var1, var2...) - create array containing variables and their values;

parameter values:

var1 : Required. Can be a string with the variable name, or an array of variables

var2 : Optional. Can be a string with the variable name, or an array of variables. Multiple parameters are allowed.

count(array, mode) - returns the number of elements in an array;

parameter values:

array : Required. Specifies the array

mode : Optional. Specifies the mode. Possible values: 0 - Default. Does not count all elements of multidimensional arrays, 1 - Counts the array recursively (counts all the elements of multidimensional arrays)

current(array) - returns the current element in an array;

parameter values:

array : Required. Specifies the array to use.

each(array) - deprecated from PHP 7.2. Returns the current key and value pair from an array;

parameter values:

array : Required. Specifies the array to use.

end(array) - sets the internal pointer of an array to its last element;

parameter values:

array : Required. Specifies the array to use.

extract(array, extract_rules, prefix) - imports variables into the current symbol table from an array;

parameter values:

array : Required. Specifies the array to use

extract_rules : Optional. The extract() function checks for invalid variable names and collisions with existing variable names. This parameter specifies how invalid and colliding names are treated. Possible values: EXTR_OVERWRITE - Default. On collision, the existing variable is overwritten, EXTR_SKIP - On collision, the existing variable is not overwritten, EXTR_PREFIX_SAME - On collision, the variable name will be given a prefix, EXTR_PREFIX_ALL - All variable names will be given a prefix,EXTR_PREFIX_INVALID - Only invalid or numeric variable names will be given a prefix, EXTR_IF_EXISTS - Only overwrite existing variables in the current symbol table, otherwise do nothing, EXTR_PREFIX_IF_EXISTS - Only add prefix to variables if the same variable exists in the current symbol table, EXTR_REFS - Extracts variables as references. The imported variables are still referencing the values of the array parameter

prefix : Optional. If EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS are used in the extract_rules parameter, a specified prefix is required. This parameter specifies the prefix. The prefix is automatically separated from the array key by an underscore character.

in_array(search, array, type) - checks if a specified value exists in an array;

parameter values:

search : Required. Specifies the what to search for

array : Required. Specifies the array to search

type : Optional. If this parameter is set to TRUE, the in_array() function searches for the search-string and specific type in the array.

key(array) - fetches a key from an array;

parameter values:

array : Required. Specifies the array to use

krsort(array, sorttype) - sorts an associative array in descending order, according to the key;

parameter values:

array : Required. Specifies the array to sort

sorttype : Optional. Specifies how to compare the array elements/items. Possible values: 0 = SORT_REGULAR - Default.Compare items normally (don't change types), 1 = SORT_NUMERIC - Compare items numerically, 2 = SORT_STRING - Compare items as strings, 3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale, 4 = SORT_NATURAL - Compare items as strings using natural ordering, 5 = SORT_FLAG_CASE -

ksort(array, sorttype) - sorts an associative array in ascending order, according to the key;

parameter values:

array : Required. Specifies the array to sort

sorttype : Optional. Specifies how to compare the array elements/items. Possible values: 0 = SORT_REGULAR - Default.Compare items normally (don't change types), 1 = SORT_NUMERIC - Compare items numerically, 2 = SORT_STRING - Compare items as strings, 3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale, 4 = SORT_NATURAL - Compare items as strings using natural ordering, 5 = SORT_FLAG_CASE -

list(var1, var2, ...) - assigns variables as if they were an array;

parameter values:

var1 : var1, var2, ...

var2 : Optional. More variables to assign values to

natcasesort(array) - sorts an array using a case insensitive "natural order" algorithm;

parameter values:

array : Required. Specifies the array to sort

natsort(array) - sorts an array using a "natural order" algorithm;

parameter values:

array : Required. Specifies the array to sort

next(array) - advance the internal array pointer of an array;

parameter values:

array : Required. Specifies the array to use

pos(array) - alias of current();

parameter values:

array : Required. Specifies the array to use

prev(array) - rewinds the internal array pointer;

parameter values:

array : Required. Specifies the array to use

range(low, high, step) - creates an array containing a range of elements;

parameter values:

low : Required. Specifies the lowest value of the array

high : Required. Specifies the highest value of the array

step : ptional. Specifies the increment used in the range. Default is 1

reset(array) - sets the internal pointer of an array to its first element;

parameter values:

array : Required. Specifies the array to use

rsort(array, sorttype) - sorts an indexed array in descending order;

parameter values:

array : Required. Specifies the array to sort

sorttype : Optional. Specifies how to compare the array elements/items. Possible values: 0 = SORT_REGULAR - Default. Compare items normally (don't change types), 1 = SORT_NUMERIC - Compare items numerically, 2 = SORT_STRING - Compare items as strings, 3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale, 4 = SORT_NATURAL - Compare items as strings using natural ordering, 5 = SORT_FLAG_CASE -

shuffle(array) - shuffles an array;

parameter values:

array : Required. Specifies the array to use

sizeof(array, mode) - alias of count();

parameter values:

array : Required. Specifies the array

mode : Optional. Specifies the mode. Possible values: 0 - Default. Does not count all elements of multidimensional arrays, 1 - Counts the array recursively (counts all the elements of multidimensional arrays)

sort(array, sorttype) - sorts an indexed array in ascending order;

parameter values:

array : Required. Specifies the array to sort

sorttype : Optional. Specifies how to compare the array elements/items. Possible values: 0 = SORT_REGULAR - Default. Compare items normally (don't change types), 1 = SORT_NUMERIC - Compare items numerically, 2 = SORT_STRING - Compare items as strings, 3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale, 4 = SORT_NATURAL - Compare items as strings using natural ordering, 5 = SORT_FLAG_CASE - Can be combined with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

uasort(array, callback) - sorts an array by values using a user-defined comparison function;

parameter values:

array : Required. Specifies the array to sort

callback : Required. A comparison function. Must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

uksort(array, callback) - sorts an array by keys using a user-defined comparison function;

parameter values:

array : Required. Specifies the array to sort

callback : Required. A comparison function. Must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument

usort(array, callback) - sorts an array using a user-defined comparison function;

parameter values:

array : Required. Specifies the array to sort

callback : Required. A comparison function. Must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument