$contacts_fields = array(
"site_telephone_2" => ['value' => "телефон 2", 'type' => 'phone'],
"site_email_2" => ['value' => "почта 2", 'type' => 'email'],
);
function decorator($name, $value, $type) {
switch($type) {
...
}
}
$res = [];
foreach($sqlResult as $row) {
if(!array_key_exists($row['id'], $res) {
$res[$row['id']] = [
'id' => $row['id'],
'name' => $row['name'],
'requests_params' => []
];
}
$res[$row['id']]['requests_params'][] = [
'fio' => $row['fio'],
'rid' => $row['rid']
];
}
echo json_encode(array_values($res));
function build_table($array){
$html = '';
foreach( $array as $key=>$value){
$html .= '<tr>';
foreach($value as $key2=>$value2){
$html .= '<td>' . htmlspecialchars($value2) . '</td>';
}
$html .= '</tr>';
}
return $html? '<table>' . $html . '</table>' : '';
}