简体   繁体   中英

how to json_encode 'php array'

i have the following array like this :

{"label":"label1","data":[[10,55],[15,32],[16,49]]}
{"label":"label","data":[[10,55],[15,32],[16,49]]} 

how to get string character (,) beetween {"label":"label1","data":[[10,55],[15,32],[16,49]]} and {"label":"label2","data":[[10,55],[15,32],[16,49]]} result like this..

{"label":"label1","data":[[10,55],[15,32],[16,49]]},
{"label":"label","data":[[10,55],[15,32],[16,49]]} 

Code

while($row = mysql_fetch_assoc($result))
{   
    $int = $row['SC'];
    $join = intval($int);
    $int2 = $row['jam'];
    $join2 = intval($int2);
    $dataset1[] = array($join2,$join);

}
for ($i=0; $i <2 ; $i++) { 
$dataset = array(label => label1, data => $dataset1);
$final = json_encode($dataset);

echo $final;

You need to put everything into another array:

$dataset = array();
foreach ($dataset1 as $d) {
    $dataset[] = array('label' => $label, 'data' => $d);
}
$final = json_encode($dataset);
echo $final;

This should output:

[{"label":"label1","data":[[10,55],[15,32],[16,49]]},
 {"label":"label","data":[[10,55],[15,32],[16,49]]}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM