Skip to content
Advertisement

array of arrays to array of objects php

I am trying to convert the associative array to an array of objects.

JavaScript

Here Is the code I have so far:

JavaScript

This code will work for a single array but not an array of arrays. If you could help with what I believe to be the loop in the setObject function.

Advertisement

Answer

EDIT for specific object:

To adhere to your existing style as close as possible without messing with array_map voodoo:

JavaScript

Original:

If you just need generic conversion, and not into specific custom objects (not exactly clear in your post?) you can try this:

JavaScript

outputs:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement