Access key and value from an array of objects
-
Hi I am trying to loop through an array of objects that looks like this
$categories = array( [0]=> { feature: 'accounting' }, [1]=> { industry : 'service'} ); $categories_copy = []; foreach ($categories as $key => $value) { array_push($categories_copy, $value); }
When I try to push it, the $value is the whole { feature : ‘accounting’ } and the $key is just 0, 1 ….
Is there a better way to loop through it so I can access the key/value pair as $key being feature and $value being ‘accounting’. Looking to get this dynamically cause the key’s may change
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Access key and value from an array of objects’ is closed to new replies.