jrquick jrquick - 1 year ago 36
PHP Question

F3: Is there a way to convert an array into an object with additional fields?

I am using Fat Free PHP to return a query using a join. Because of this the results have extra fields from another table. I want to be able to convert the array to objects (ie arrayToObjects) but I want the additional fields to persist. I would also like this to return an instance of my class, not an stdClass.

I tried adding the additional fields to the php model but it loses the values when I pass the mysql result into arrayToObjects().

Is this achievable?


I am not huge fan of my eventual solution but I added the values manually to the object from the array.

For example:

object = new Object();
object->id = array['id']
object->name = array['name']