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;
1 Answer 1
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]]}]
answered Nov 21, 2014 at 2:18
Barmar
789k57 gold badges555 silver badges669 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-php
mysqli_..., becausemsql_...has been removed from PHP.$dataset1[$i]in that for loop? Or are you seriously dumping the same thing over and over?$label = labeldoing? Should that be$label[] = $row['label']?