You can use the array_map
to browse the array created with json_decode
and apply the change wherever you want:
$string = '{"3":{"tipo":"Premium","valor":"100","quantidade":"200","vendas":"0","status":"1"},"1":{"tipo":"Arena","valor":"50","quantidade":"200","vendas":"0","status":"1"}}';
// transforma em array
$jsonArray = json_decode($string, true);
$jsonArray = array_map(function($e){
$e['vendas'] = 10; // altera a venda para 10
$e['status'] = 2; // altera o status para 2
return $e;
}, $jsonArray);
// transforma em json novamente
echo json_encode($jsonArray);
Check it out at Ideone
Another option is to use the array_walk
:
array_walk($jsonArray, function(&$e, $k){
$e['vendas'] = 10; // altera a venda para 10
$e['status'] = 2; // altera o status para 2
});
If you are going to change the values manually:
$jsonArray = json_decode($string, true); // transforma em array
$jsonArray[3]['vendas'] = 20; // altera determinado valor
echo json_encode($jsonArray); // transforma em json
When you say "guy" means we can create a column like
json
?!– LipESprY
"type" is the die type of the column, instead of using VARCHAR, use JSON
– Costamilam
@Guilhermecostamilam is true! I just had a test at the bank! I didn’t know that! I thought only in the new version on Nosql that this existed!
– Andrei Coelho
@Lipespry the type is JSON! =)
– Andrei Coelho
I’m gonna start using that brace! Thanks bro!
– Andrei Coelho
@Andreicoelho suspected from the beginning! (Our stupidity! You have the link’s Disgrama in the answer)
– LipESprY