
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
PHP array_push to Create an Associative Array
To create associative arrays in PHP, use [] brackets. You don't need to use array_push().
Example
<!DOCTYPE html> <html> <body> <?php $emp= (object) [ 'employeeId'=>"101", 'employeeFirstName'=>"John", 'employeeLastName'=>"Doe", 'employeeCountryName'=>"AUS" ]; $employeeDetails[] = [ 'emp_id' => $emp->employeeId, 'emp_first_name' => $emp->employeeFirstName, 'emp_last_name' => $emp->employeeLastName, 'emp_country_name' => $emp->employeeCountryName ]; print_r(array_values($employeeDetails)); ?> </body> </html>
Output
Array ( [0] => Array ( [emp_id] => 101 [emp_first_name] => John [emp_last_name] => Doe [emp_country_name] => AUS ) )
Advertisements