Categories
PHP

Natural Order Sorting

Natural ordering is an alphanumeric sort order, it treated multiple digits as a single character. The natsort() and natcasesort functions do not take flags and are the same as called sort() (or sort(), rsort() etc.) with the SORT_NATURAL flag.

Categories
PHP

Sorting Nested Arrays

PHP sorting functions can not perform a deep sort on nested arrays. To solve this problem, create a recursive function that calls any PHP sorting function and sorts a nested array deeply (by calling a sorting function recursively).

Categories
PHP

Sorting Multidimensional and Multiple Arrays with array_multisort

In this tutorial, you’ll learn how to use the array_multisort() function to sort multiple arrays depending on the sort order of another array. You’ll also learn to use this function to sort multidimensional arrays in one or more dimensions.

Categories
PHP

Sorting with user-defined comparison function

The sorting functions, described in previous tutorials, sort elements in alphabetic, numeric, or alphanumeric order. To sort elements based on user-defined criteria, PHP provides three functions: usort, uasort, and uksort.

Categories
PHP

Sorting Associative Arrays

It’s often desirable to keep the key/value associations when sorting associative arrays. To maintain the key/value association the asort( ) and arsort( ) functions are used. Rather than sort on element values, the ksort( ) and krsort( ) functions rearrange elements in an array by sorting on the keys or the indexes.

Categories
PHP

Sorting Arrays

The simplest array-sorting functions are sort( ) and rsort( ), which rearrange the elements of the subject array in ascending and descending order, respectively:

Categories
PHP

Count Array Elements and Find Min or Max Values

How to count elements of multidimensional or nested array, count the frequency of unique values in an array, and find the maximum and minimum values in an array.

Categories
PHP

Explode and Implode Functions

Learn how to convert arrays into strings and strings into arrays with the help of two PHP functions implode() and explode().

Categories
PHP

Array Internal Pointers

Along with the keys and the associated values stored in an array, PHP maintains an internal index that points to the current element in the array.

Categories
PHP

Array Iteration

The easiest way to iterate through each element of an array is with foreach. The foreach statement lets you run a code block once for each element in an array.