Advertisement
tommasov

Per Francesco Ingrosso

Feb 18th, 2021
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2. $contents = '{
  3.    "intents": [{
  4.        "name": "HelloIntent",
  5.        "samples": ["Ciao", "Salve"],
  6.        "responses": ["Ciao", "Buongiorno"]
  7.    },
  8.    {
  9.        "name": "GoodbyeIntent",
  10.        "samples": ["Addio", "Arrivederci"],
  11.        "responses": ["Grazie per averci contattato!","Buona giornata !"]
  12.    }
  13.    ],
  14.     "defaults":["Non ho capito", "Scusa, non ho capito"]
  15. }';
  16. $contentsDecoded = json_decode($contents, true);
  17.  
  18. $value1 = "Stattbuon";
  19. $value2 = "Puratte";
  20.  
  21. foreach($contentsDecoded['intents'] as $key => $intenti){
  22.  
  23.  
  24.     if($intenti['name'] == "GoodbyeIntent"){
  25.  
  26.         array_push($contentsDecoded['intents'][$key]['samples'], $value1);
  27.         array_push($contentsDecoded['intents'][$key]['responses'], $value1);
  28.     }
  29. }
  30.  
  31. $json = json_encode($contentsDecoded);
  32.  
  33. print_r($json);
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement