I am sending an array over HTTP POST to backend API which is PHP.
js
var form_data = [];
for (var k = 0; k < $scope.Tablelist.length; k++){
if($scope.Tablelist[k].selected == true){
var id = $scope.Tablelist[k].id;
var docno = $scope.Tablelist[k].quote_no;
form_data.push({id: id, docno:docno})
}
}
if(form_data.length>0){
$http({
method: 'POST',
url: "api/purchase/purchase.php",
data: {
modul: 'PRICE',
action: 'delete',
form_data: form_data,
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
})
PHP
$form_data = (array)$request->form_data;
foreach ($form_data as $key => $value) {
echo "Key: $key; Value: $value";
}
it gave me an error Object of class stdClass could not be converted to string.
I am trying to get the value of id and docno of each array.
How can i do that?
var_dump($form_data)
"array(3) {↵ [0]=>↵ object(stdClass)#3 (2) {↵ ["id"]=>↵ string(1) "6"↵ ["docno"]=>↵ string(5) "test4"↵ }↵ [1]=>↵ object(stdClass)#4 (2) {↵ ["id"]=>↵ string(1) "7"↵ ["docno"]=>↵ string(5) "test3"↵ }↵ [2]=>↵ object(stdClass)#5 (2) {↵ ["id"]=>↵ string(1) "4"↵ ["docno"]=>↵ string(5) "test2"↵ }↵}↵"
var_dump($request->form_data)
"array(3) {↵ [0]=>↵ object(stdClass)#3 (2) {↵ ["id"]=>↵ string(1) "6"↵ ["docno"]=>↵ string(5) "test4"↵ }↵ [1]=>↵ object(stdClass)#4 (2) {↵ ["id"]=>↵ string(1) "7"↵ ["docno"]=>↵ string(5) "test3"↵ }↵ [2]=>↵ object(stdClass)#5 (2) {↵ ["id"]=>↵ string(1) "4"↵ ["docno"]=>↵ string(5) "test2"↵ }↵}↵"
var_dumporprint_rof$form_dataor$request->form_data?$form_dataor$request->form_data$valueis not a string.$value->docnoand$value->idwill work.