This is the static multidimension array and i converted to json.
$mailmsg = array(
'type'=> 'line',
'data' => array(
'labels' => array("1","2","3","4","5"),
'datasets' => array(array("label"=>"A","fill"=>"false","yAxisID"=>"A","borderColor"=>"#bae755","data"=>array(100, 96, 84, 76, 69)),array("label"=>"B","fill"=>"false","yAxisID"=>"B","borderColor"=>"#55bae7","data"=>array(1, 1, 1, 1, 0)),array("label"=>"C","fill"=>"false","yAxisID"=>"C","borderColor"=>"#e755ba","data"=>array(5, 15, 10, 10, 0)))),
' '=>array("scales"=>array("yAxes"=>array(array("scaleLabel"=>array("display"=>"true","labelString"=>"Prn1"),"id"=>"A","type"=>"linear","position"=>"left"),array("scaleLabel"=>array("display"=>"true","labelString"=>"Prn2"),"id"=>"B","type"=>"linear","position"=>"left"),array("scaleLabel"=>array("display"=>"true","labelString"=>"Prn3"),"id"=>"C","type"=>"linear","position"=>"left")))
));
echo $json = json_encode((object)$mailmsg, JSON_NUMERIC_CHECK);
Result:
{
"type": "line",
"data": {
"labels": ["1","2","3","4","5"],
"datasets": [{
"label": "A",
"fill": "false",
"yAxisID": "A",
"borderColor": "#bae755",
"data": [100, 96, 84, 76, 69]
}, {
"label": "B",
"fill": "false",
"yAxisID": "B",
"borderColor": "#55bae7",
"data": [1, 1, 1, 1, 0]
}, {
"label": "C",
"fill": "false",
"yAxisID": "C",
"borderColor": "#e755ba",
"data": [5, 15, 10, 10, 0]
}]
},
"options": {
"scales": {
"yAxes": [{
"scaleLabel": {
"display": "true",
"labelString": "Prn1"
},
"id": "A",
"type": "linear",
"position": "left"
}, {
"scaleLabel": {
"display": "true",
"labelString": "Prn2"
},
"id": "B",
"type": "linear",
"position": "left"
}, {
"scaleLabel": {
"display": "true",
"labelString": "Prn3"
},
"id": "C",
"type": "linear",
"position": "left"
}]
}
}
}
I need to above static array to change dynamically using foreach.
Nick
147k23 gold badges67 silver badges106 bronze badges
-
2Didn't understand the question what do you mean change dynamicallyErubiel– Erubiel2018年08月30日 04:47:07 +00:00Commented Aug 30, 2018 at 4:47
-
I have the data sets array separetely. I want to display the expected result by using the individual arraysKames P– Kames P2018年08月30日 04:53:08 +00:00Commented Aug 30, 2018 at 4:53
-
I still don't get it. Maybe you should just describe the results by giving examples, preferably examples that are much smaller than the above, unless that size is really necessary for something.Ulrich Eckhardt– Ulrich Eckhardt2018年08月30日 05:58:56 +00:00Commented Aug 30, 2018 at 5:58
1 Answer 1
just pass the reference to the specific data in the array:
foreach($mailmsg['data']['datasets'] as $key => $value){
}
Sign up to request clarification or add additional context in comments.
Comments
lang-php