fork download
  1. <?php
  2.  
  3. $items = array(
  4. 'valor'=> "1.95",
  5. 'ativo'=> '1'
  6. ),
  7. 'valor' => '9.90',
  8. 'ativo' => '0'
  9. ),
  10. );
  11. $itemsJson = json_encode($items);
  12. $itemsBack = json_decode($itemsJson);
  13. var_dump($itemsBack[0]->valor); // aqui vemos que é string
  14. // vamos converter
  15. $hey = (float) $itemsBack[0]->valor;
  16. var_dump($hey);
  17. $hey = (int) $itemsBack[0]->ativo;
  18. var_dump($hey);
Success #stdin #stdout 0.01s 52480KB
stdin
Standard input is empty
stdout
string(4) "1.95"
float(1.95)
int(1)