http://php.net/manual/en/function.array-reverse.php:
$newArray = array_reverse($theArray, true);
The important part is the true
parameter, which preserves the keys.
Not convinced? You can see it in action on this codepad exampole.
More Related Contents:
- multiple assigning array in foreach?
- How to get the first key of many duplicated json key? [duplicate]
- How can I access an array/object?
- Sort an Array by keys based on another Array?
- PHP syntax for dereferencing function result
- How to filter an array by a condition
- Access array returned by a function in php
- Are arrays in PHP copied as value or as reference to new variables, and when passed to functions?
- PHP Multiple Checkbox Array
- What is so wrong with extract()?
- How to re-index the values of an array in PHP? [duplicate]
- How to use a string as an array index path to retrieve a value?
- PHP Difference between array() and []
- filter values from an array similar to SQL LIKE ‘%search%’ using PHP
- Type hinting – specify an array of objects
- Check if string contains a value in array [duplicate]
- Convert an associative array to a simple array of its values in php
- CSV to Associative Array
- How to pass an array via $_GET in php?
- How to create an empty array in PHP with predefined size?
- PHP – Find parent key of array
- Warning: array_combine(): Both parameters should have an equal number of elements
- Merge multiple associative arrays and add missing columns with a default value
- Find common values in multiple arrays with PHP
- Add elements to array which has gapped numeric keys to form an indexed array / list
- Return only duplicated entries from an array (case-insensitive)
- How can I add a condition inside a php array?
- Isolate comma-separated values, remove duplicates and empty values, then sort
- PHP: Check for duplicate values in a multidimensional array
- array_diff to compare two associative arrays