views:

55

answers:

1

With this:

private function jsonArray($object)
{
  $json = array();

  if(isset($object) && !empty($object))
  {
    foreach($object as $obj)
    {
      ...
    }
  }

  return $json;

}

We iterate over an object with success. We use PDO::fetch[FETCH_OBJ] and it works.

What if, we want to iterate over an array of objects like the one returned by a fetchAll with the FETCH_OBJ attribute? Should the syntax be the same?

Thanks in advance, MEM

+1  A: 

Can be as simple as having yet another foreach loop to iterate the array and then ("inside" that loop) do the same thing as before.

foreach($objects as $obj) {
  foreach($obj as $property) {
    ...
  }
}
VolkerK
I tried before, but no luck. Your answer still is valid. But the issue may rely on something else. :) Need to remake this question.
MEM
@VolkerK - hm... this same issue, after some dump findings: http://stackoverflow.com/questions/3736455/jquery-autocomplete-plugin-fetch-works-fetchall-doesnt
MEM