-2

I am trying to output the information about a particular variable of decoded json those being tags but am having difficulty outputting anything I get syntax error unexpected bracket after var_dump statement what do I need to add / change thanks all

$con=mysqli_connect("localhost","root","","json_map");
$response = array(); 
$res=array(); 
$json = file_get_contents('C:\Users\Richard\Desktop\test.json'); 

if($json!=null){ 
$decoded=json_decode($json,true); 
//$decode= var_dump($decoded); 
//$ss=$decode["array"]; 
//echo $decoded['number']; 

if(is_array($decoded["configurationItems"])) 
{ 
    foreach($decoded["configurationItems"] as $configurationItems) 
    //for($i=0;$i>sizeof($decoded["configurationItems"]);$i++) 

  { 
var_dump($configurationItems['tags']);


}

}

?> 
Richard Hewitt
  • 345
  • 1
  • 5
  • 22
  • The if(is_array... needs to be closed also, last bracket is for the foreach – Dimas Pante Jan 19 '15 at 12:23
  • 1
    I think is better for you to start writing code using a free IDE (that automatically highlights many errors like yours). – gp_sflover Jan 19 '15 at 12:27
  • This question and [another of your questions](http://stackoverflow.com/questions/27941198/undefined-index-mysqli-ston) may show that a lack of indentation is making the structure of your code confusing for you. You need to develop something of an OCD tendency regarding the neatness of your code, including switching on invisible characters in your editor, so you can check your tabs/spaces are nigh-on perfect. – halfer Jan 19 '15 at 12:59

2 Answers2

2

use inside the for each

foreach($decoded["configurationItems"] as $configurationItems) 
{
var_dump($configurationItems['tags']);
}

OR

var_dump($decoded["configurationItems"]);
Arun Kumar
  • 1,607
  • 1
  • 18
  • 33
1

You have following errors:

  • close statements with a ;
  • Need to close if's bracket }

Try this code:

if(is_array($decoded["configurationItems"])) 
{ 
    foreach($decoded["configurationItems"] as $configurationItems) 
    { 
      var_dump($configurationItems['tags']);//Corrected
    }//End of foreach

}//End of IF
Manwal
  • 23,450
  • 12
  • 63
  • 93
  • I have tried your code thankyou but I am getting an unexpected end of file error – Richard Hewitt Jan 19 '15 at 12:28
  • Have you used `}?>` ??? You should put space between them try `} ?>`. And see http://stackoverflow.com/questions/11482527/parse-error-syntax-error-unexpected-end-of-file-in-my-php-code – Manwal Jan 19 '15 at 12:31
  • I did thanks still no luck what might help is if you look at this question which gives more info about why i'm doing what i am doing http://stackoverflow.com/questions/28022131/undefined-index-name – Richard Hewitt Jan 19 '15 at 12:45