array('funcname' => DATA)) // so take the first element of the 'result' array $func = key($data['result']); $data = reset($data['result']); $first = reset($data); $single = ! is_array($first); $content = ''; if($single) { $content .= ""; } else { $columns = array_keys($first); $content .= ''; foreach($columns as $k) { $content .= ""; } $content .= ''; } $content .= ''; if($single) { foreach($data as $k => $v) { $content .= ""; } } else { foreach($data as $row) { $content .= ''; foreach($columns as $c) { $v = print_r(isset($row[$c]) ? $row[$c] : '', true); $limit = 50; if(strlen($v) > $limit) { $v = substr($v, 0, $limit).' [...]'; } $content .= ""; } $content .= ''; } } $content .= '
FieldValue
$k
$k".print_r($v, true)."
$v
'; return array( 'title' => $func, 'content' => $content, 'status' => 'success', ); } private function error($data) { $code = $data['error']['code']; $name = $data['error']['name']; $msg = $data['error']['reason']; return array( 'title' => 'Error', 'content' => "

[$code] $name : $msg

", 'status' => 'warning', ); } private function failure($data) { $code = $data['failure']['code']; $name = $data['failure']['reason']; return array( 'title' => 'Failure', 'content' => "

[$code] $name

", 'status' => 'danger', ); } public function render($data) { $type = key($data); if (method_exists($this, $type)) { $context = call_user_func_array(array($this, $type), array($data)); } else { $context = array( 'title' => 'Formatter error', 'content' => '

Unable to render this

', 'status' => 'info', ); } $html = file_get_contents('template.html'); foreach($context as $k => $v) { $html = str_replace("{{ $k }}", $v, $html); } echo $html; } }