steven smith steven smith - 3 months ago 9x
JSON Question

Why cant I use dots in arrays?

I wanted to try something out with an API from a company. I wanted to put their data into my database. But I've run into a problem. The API has one JSON object called "". But I can't use dots in my array for some reason?

Here is the code:

foreach ($data[1]['hits']['hits'] as $row) {
"name" => $row['fields']['name'][0],
"date" => $row['fields']['start'][0],
"lang_long" => "test",
It is this one! -> "country" => $row['fields'][''][0],
"genres" => $row['fields']['genres'][0],
"desc" => $row['fields']['description'][0],
"logo" => $row['fields']['logo'][0],
"header_pic" => $row['fields']['header'][0]

\everything else works in the PHP
And here is a piece of the JSON: [

How can I get this to work? Can I use the "explode" method?

This is the full JSON:


Even with the answer @Prototype Chain gave it is giving me this error:
Notice: Undefined index: venue in /home/ubuntu/workspace/pop.php on line 18


The code works fine. After debugging I found that, there is no key/index for the array elements $data[1]['hits']['hits'][50] and $data[1]['hits']['hits'][51]. Since there is no index, its throwing notice.

You can add @before the variable to suppress the notice or check the condition if the index exixts.

"country" => @$row['fields'][''][0],

"country" => isset($row['fields']['']) ? $row['fields'][''][0] : '',

// run this code for testing.

ini_set('display_errors', 1);
$jsondata = file_get_contents('');
$data     = json_decode($jsondata, true);
foreach ($data[1]['hits']['hits'] as $row) {
   // echo $row['fields']['name'][0].'=>'.@$row['fields'][''][0].'<br/>';
   $array[]= array(
        "name" => $row['fields']['name'][0],
        "country" => isset($row['fields']['']) ? $row['fields'][''][0] : ''
echo "<pre>";