chrisstump
3/6/18 at 9:43 am
PHP
PHP: Building A Custom Multi-Dimensional Array From an Array of Objects
This example loops through an array of objects ($users) to build a custom multi-dimensional array ($people).
// set a counter $i = 0; // setup an array $people = array(); // loop through existing array of objects foreach($users as $user) { $people[$i]['firstName'] = $user->firstName; $people[$i]['lastName'] = $user->lastName; $i++; } // output the array print_r($people);
Copy Snippet to Clipboard
Don't Have an Account?
Stop digging through old code examples. Get organized. Get Code Snipper.
Learn More
Start Free 14 Day Trial