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
Return an array with numeric keys PHP?
For this, use foreach loop along with [] and implement arary_values() method.
Example
<!DOCTYPE html>
<html>
<body>
<?php
$details = [
[
"id" => "10001",
"firstName" => "John",
"lastName" => "Doe"
],
[
"id" => "10002",
"firstName" => "David",
"lastName" => "Miller"
]
];
foreach ($details as $k=> $v) {
$someDetails[$v['id']][] = ['LASTNAME' => $v['lastName'], 'FIRSTNAME'=> $v['firstName']];
}
print_r(array_values($someDetails));
?>
</body>
</html>
Output
Array ( [0] => Array ( [0] => Array ( [LASTNAME] => Doe [FIRSTNAME] => John ) ) [1] => Array ( [0] => Array ( [LASTNAME] => Miller [FIRSTNAME] => David ) ) )
Advertisements