PHP arrays Tutorials and Examples

PHP sort associative array using custom compare function

PHP associative array can be sorted using custom user compare function while maintaining index association using uasort. The function is passed two values and it read more

PHP array map example

PHP array map applies the callback function to one or more arrays. In callback we can use a function or anonymous function. Here are some read more

PHP check if key exists in array

Checking if a key exists in an array and possibly has a non empty value are frequently used when writing php code. Accessing value of read more

PHP – check if a value is in array

Checking if a value exists in array is frequently used in php. PHP in_array() can be used for this check. By default it does not read more

PHP – convert array to associative array

Convert using array_flip() This works if we need index as value. Using foreach iterator In case we need to set associative array value using array read more

PHP array foreach – code snippets

PHP array – foreach loop on values PHP array – foreach loop on index,values PHP array – foreach loop for modification PHP associative array – read more

PHP – print array in one line

At times for large array values we want to log them in one line for better readability. Logging an array in one line is also read more