PHP - json - 函数调用问题

I am having two functions printBefore(json1) and printAfter(json2). Both are having json object as parameter.jsons are coming from database. They are parsing json and displaying it in correct format. But it is taking more than 30 seconds.

When I removed functon and displays json as it is. It is not taking time more than second.

I am not able isolate problem. Please Help.

foreach ($records as $record) {
        echo '<tr>';
        echo '<td>' . $userNames['users'][$record->uid] . '</td>';
        echo '<td>' . $userNames['users'][$record->uid] . '</td>';
        echo '<td>' . $record->val . '</td>';
        echo '<td>' . $record->mi. '</td>';
        echo '<td>' . $record->created_on . '</td>';
        echo '<td>' . printBefore($record->newData) . '</td>';
        echo '<td>' . printAfter($record->oldData) . '</td>';
        echo '</tr>';
    }

Code for printAfter($oldData)

 $oldData = json_decode($oldData, true);
  if (isset($OldData['sub_category'])) {
        $str = $str . "|Category : " . $this->category[$OldData['sub_category']] . "|";
    }

code for PrintBefore($newData)

 $newData = json_decode($newData, true);
  if (isset($newData['sub_category'])) {
        $str = $str . "|Category : " . $this->category[$newData['sub_category']] . "|";
    }