php - Need to fetch values from Angular JS array -
i using mvc model in php. getting following string view layer (this angular.js array getting string):
[ { "name" : "item", "price" : "123", "quantity" : 12, "id" : 1 }, { "name" : "hhh", "price" : "000", "quantity" : 12, "id" : 2 }, { "name" : "kk", "price" : "88", "quantity" : 12, "id" : 3 } ]
how can extract values of name, price, quantity , id string , put insert query?
this known serialized array, meaning javascript array in string form (json). can use php's json_decode
function deserialize string, there can use normal array:
$json='[ { "name" : "item", "price" : "123", "quantity" : 12, "id" : 1 }, { "name" : "hhh", "price" : "000", "quantity" : 12, "id" : 2 }, { "name" : "kk", "price" : "88", "quantity" : 12, "id" : 3 } ]'; $array=json_decode($json); foreach ($array &$value) { var_export($value->name); var_export($value->price); var_export($value->quantity); var_export($value->id); }
the above should display values in array. i'm not sure mean "put insert query", above access data.
Comments
Post a Comment