Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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"
}Advertisements