Using json_encode on objects in PHP (regardless of scope)
问题 I'm trying to output lists of objects as json and would like to know if there's a way to make objects usable to json_encode ? The code I've got looks something like $related = $user->getRelatedUsers(); echo json_encode($related); Right now, I'm just iterating through the array of users and individually exporting them into arrays for json_encode to turn into usable json for me. I've already tried making the objects iterable, but json_encode just seems to skip them anyway. edit : here's the var