
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Reset keys of array elements using PHP ?
To reset keys of array elements using PHP, the code is as follows−
Example
<?php $arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110"); var_dump ($arr); $res = array_values($arr); var_dump ($res); ?>
Output
This will produce the following output−
array(4) { ["p"]=> string(3) "150" ["q"]=> string(3) "100" ["r"]=> string(3) "120" ["s"]=> string(3) "110" } array(4) { [0]=> string(3) "150" [1]=> string(3) "100" [2]=> string(3) "120" [3]=> string(3) "110" }
Example
Let us now see another example −
<?php $arr = array( 8=>"Ben", 4=>"Kevin", 7=>"Mark", 3=>"Hanks"); var_dump ($arr); $res = array_values($arr); var_dump ($res); ?>
Output
This will produce the following output−
array(4) { [8]=> string(3) "Ben" [4]=> string(5) "Kevin" [7]=> string(4) "Mark" [3]=> string(5) "Hanks" } array(4) { [0]=> string(3) "Ben" [1]=> string(5) "Kevin" [2]=> string(4) "Mark" [3]=> string(5) "Hanks" }
- Related Articles
- Return an array with numeric keys PHP?
- Sort multidimensional array by multiple keys in PHP
- reset() function in PHP
- Remove duplicated elements of associative array in PHP
- Removing empty array elements in PHP
- Removing duplicate elements from an array in PHP
- PHP print keys from an object?
- Find elements of array using XOR of consecutive elements in C++
- PHP program to find missing elements from an array
- PHP script to get all keys from an array that starts with a certain string
- PHP Call methods of objects in array using array_map?
- Sort object array based on another array of keys - JavaScript
- Deep count of elements of an array using JavaScript
- Merge two arrays keeping original keys in PHP
- How to generate child keys by parent keys in array JavaScript?

Advertisements