Jump to content

Efficiently typecasting an array as a custom object?


Man In Tan

Recommended Posts

I need to typecast an array as an object, so I can use methods the deal with the former array's data. However, direct typecasting results in an instance of the stdClass class, which is not even remotely helpful with custom methods. Currently, I'm using a foreach statement to handle the conversion process, as shown below, but from what I've read, this is a slow way to handle these kinds of data processing. Is there a more efficient way?

<?php foreach($array as $key => $value){ $object->$key = $value; }

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...