Q:

How to add content recursively to an array?

I have a file with multiple lines, I need to iterate each line and save it into an array.   Actually this is my code:
while(($line = fgets($fh)) !== false)
{
      $obj = json_decode($line);

      $content['trace']= array(
             'message' => $obj->trace->details->{"[message]"},
      );

}

Now If I have for example two lines:

Line 1
Line 2

In the $content array returned after the end of the while I can see only the content of Line2. Should I use array_push() or there is something else?

A:

It depends on what you want the resulting array to look like.  To build a message array:
$content['trace']['message'][] = $obj->trace->details->message;

Or to build multiple arrays each with a message key:
$content['trace'][]['message'] = $obj->trace->details->message;

