Advertisement
BrunoDeOliveira

Add new property to object - Solution 2

Oct 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $dados = '[
  5. {
  6. "id":1,
  7. "descricao":"Tipo de Registro 01",
  8. "status_op":"status de op 01",
  9. "status_atividade":"status de atividade 01",
  10. "exige_atividade":false,
  11. "acao_op":"Nenhum",
  12. "acao_atividade":"Nenhum",
  13. "tipo_registro_campos":[
  14. {
  15. "id":3,
  16. "nome":"teste",
  17. "tipo_dado":"Texto",
  18. "comportamento":"CodigoRastreavel",
  19. "tamanho":10,
  20. "obrigatorio":false,
  21. "id_tipo_registro":1
  22. }
  23. ]
  24. },
  25. {
  26. "id":2,
  27. "descricao":"Teste 2",
  28. "status_op":"status 01",
  29. "status_atividade":"status 02",
  30. "exige_atividade":false,
  31. "acao_op":"Nenhum",
  32. "acao_atividade":"Nenhum",
  33. "tipo_registro_campos":[
  34. {
  35. "id":6,
  36. "nome":"Label 1",
  37. "tipo_dado":"Numerico",
  38. "comportamento":"Nenhum",
  39. "tamanho":null,
  40. "obrigatorio":true,
  41. "id_tipo_registro":2
  42. },
  43. {
  44. "id":7,
  45. "nome":"Label 2",
  46. "tipo_dado":"Boolean",
  47. "comportamento":"Nenhum",
  48. "tamanho":null,
  49. "obrigatorio":false,
  50. "id_tipo_registro":2
  51. },
  52. {
  53. "id":8,
  54. "nome":"Label 3",
  55. "tipo_dado":"Texto",
  56. "comportamento":"Nenhum",
  57. "tamanho":null,
  58. "obrigatorio":false,
  59. "id_tipo_registro":2
  60. }
  61. ]
  62. }
  63. ]';
  64.  
  65. $atividades = json_decode($dados);
  66.  
  67. foreach ($atividades as $i => $a) {
  68. for($j=0; $j< count($a->tipo_registro_campos); $j++) {
  69. $atividades[$i]->tipo_registro_campos[$j]->valor = null;
  70. }
  71. }
  72.  
  73. var_dump($atividades);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement