Mysql
 sql >> Database >  >> RDS >> Mysql

PHP:ottieni i dati da db a JSON

Solo così puoi iniziare,

<?php
    $outArr = array();
    $arr1 = array(0 => array('ID' => '01', 'FIRSTNAME' => 'Google'));
    $arr2 = array(0 => array('ID' => '01', 'FIRSTNAME' => 'JOHN', 'SURNAME' => 'DOE'),
        1 => array('ID' => '01', 'FIRSTNAME' => 'NewJOHN', 'SURNAME' => 'NewDOE'));

    foreach ($arr1 as $key => $compArr) {
        $companyId = $compArr['ID'];
        $outArr[$compArr['FIRSTNAME']] = '';
        foreach ($arr2 as $arr2key => $employeeArr) {
            if ($employeeArr['ID'] == $companyId) {
                $outArr[$compArr['FIRSTNAME']][] .= $employeeArr['FIRSTNAME'];
            }
        }
    }
    echo json_encode($outArr);
    exit;
?>