I’m trying to get specific value by array name:
<?php
$json = json_decode($_POST['json'], true);
print_r($json);
?>
I’m getting this varray:
Array
(
[0] => Array
(
[name] => pav
[value] => g
)
[1] => Array
(
[name] => ppav
[value] => f
)
[2] => Array
(
[name] => kiekis
[value] => g
)
[3] => Array
(
[name] => kaina
[value] => g
)
[4] => Array
(
[name] => ppav
[value] => f
)
[5] => Array
(
[name] => kiekis
[value] => g
)
[6] => Array
(
[name] => kaina
[value] => f
)
[7] => Array
(
[name] => ppav
[value] => g
)
)
Tried using foreach function, but cant get specific value:
foreach ($json as $key => $value) {
echo "name".$key['name']." value".$value['value']."<br />";
}
It prints all array values:
name value<br />name valueasd<br />name valueasd<br />name values<br />name values<br />name values<br />name values<br />name valuea<br />name valueasd<br />name valued<br />
But I cant select specific value by name to add to nysql. How to do that?
Following is the tested code
output of the code is given below and you can see that exactly same array as yours is converted into associative array, there is one problem as your array has repeated names eg. ppav or kiekis so there will only 1 index for kiekis or ppav having the latest value.