I need to do this: There is a config

"test": { "x": "120", "y": "50", "size": "20", "color": "#FFAA00", "text": "Цена {$values}" } 

I need to when I called $config['test'][text] , output: Price ... (variable value)

  • For this there is a function json_decode - the second parameter of the function if you put in true you will have an array. - And
  • lol, i'm talking about the fact that i need to output the value of the $ values ​​variable - I. Ageyev

1 answer 1

need to display the value of the $ values ​​variable

Use the concatenation operator (dot) :

 $values = '123'; $json = '{"test": { "x": "120", "y": "50", "size": "20", "color": "#FFAA00", "text": "Цена ' . $values . '" }}'; $config = json_decode($json, true); echo $config['test']['text']; // Цена 123 
  • It doesn’t work for me, that’s what Цена ' . $valute . ' does Цена ' . $valute . ' Цена ' . $valute . ' Цена ' . $valute . ' - I. Ageyev 5:06
  • @ I.Ageyev copy the code from my example entirely, and consistently change it to fit your needs. - Edward