convert a javascript code snippet to php -
i have javascript code this.i want convert code in php.as beginer in php struggling convert code snippet in php.how can perform this?
java script
var view = [{data: [["1:24:22", 969],["1:24:42", 970],["1:25:03", 972]]}, {data: [["2:35:22", 969],["2:44:42", 970],["2:55:03", 972]]}]; view.foreach(function (r) { k = 0; r.data.foreach(function (d) { d[0] = ++k; }); }); tried
php
$view = [{data: [["1:24:22", 969],["1:24:42", 970],["1:25:03", 972]]}, {data: [["2:35:22", 969],["2:44:42", 970],["2:55:03", 972]]}];
below code php version of javascript. $view
taken json string , can manipulated below. appreciate @marty's comment, think you.
$view = '[{"data": [["1:24:22", "969"],["1:24:42", "970"],["1:25:03", "972"]]}, {"data": [["2:35:22", "969"],["2:44:42", "970"],["2:55:03", "972"]]}]'; $view = json_decode($view); foreach($view $r){ $k=0; foreach($r->data $d){ $d[0] = ++$k; } }
Comments
Post a Comment