0

I have this json (a part of it)

{
  "actual": {
        "image": {
        "title":"Pronostico 3 dias"

        },
    "forecast":{
        "txt": {
        "fecha":"5:08 PM -03",
        "forecastdia": [
        {
        "dia":0,
        "icon":"partlycloudy",
        "title":"Tuesday",
        "pop":"20"
        }
        ,
        {
        "dia":1,
        "icon":"nt_partlycloudy",
        "title":"Tuesday Night",
        "pop":"20"
        }
        ,
        {
        "dia":2,
        "icon":"clear",
        "title":"Wednesday",
        "pop":"0"
        }
        ,
        {
        "dia":3,
        "icon":"nt_clear",
        "title":"Wednesday Night",
        "pop":"0"
        }
        ,
        ]
        },

}

I need to separate in variables with php the array forecastdia. For example

  1. $icon0=partlycloudy
  2. $icon1=nt_partlycloudy

How I can do that? Someone can guide me? Best regards

Carina

CVB
  • 309
  • 1
  • 3
  • 9
  • Let me translate `I need to separate in variables with php the array` > I need a separate variable for each item in the JSON data. – ArtisticPhoenix Aug 14 '18 at 21:33
  • ^ that said, it's generally a bad idea because it pollutes your variable space and you lose any structure contained within the JSON data, its better to use `$data = json_decode($json, true)` which will give you an associate array and retain the structure of the data. – ArtisticPhoenix Aug 14 '18 at 21:34
  • A good example is to use `$icon64` you would have to know beforehand there would be an `$icon64` without knowing that you will have to check `$icon{n}` each time before using it. Where as using an array, its very simple to loop over the items without knowing how many you have. I hope that makes sense. – ArtisticPhoenix Aug 14 '18 at 21:36

0 Answers0