1

This is the var_dump of my array (var_dump $syn3):

array(1) { 
     ["@attributes"]=> 
     array(2) { 
         ["date"]=> string(10) "Sun 16 Oct" 
         ["time"]=> string(5) "21:45" 

     } 
}

I am trying to pull out date and time:

foreach($array2 as $syn3) {     
    $datemovie = $syn3['@attributes']['date'];
    $timemovie = $syn3['@attributes']['time'];

}

The above results in

PHP Notice: Undefined index: @attributes in

I don't get it - this should have worked. Where is my mistake?

10
  • I think the issue with @ as a key. Commented Oct 17, 2016 at 10:28
  • 1
    I dont think @ is the problem. eval.in/661838. What is the actual array ($array2)? Commented Oct 17, 2016 at 10:31
  • show us $array2 Commented Oct 17, 2016 at 10:32
  • But I'm not working with $array2. I want to work with $syn3 Commented Oct 17, 2016 at 10:32
  • try with foreach inside foreach.: 3v4l.org/JsZdh Commented Oct 17, 2016 at 10:33

2 Answers 2

1
<?php
$array = array("@attributes"=>array("date"=>'Sun 16 Oct', "time"=>'21:45'));
var_dump($array);
$datemovie = $array['@attributes']['date'];
$timemovie = $array['@attributes']['time'];
Sign up to request clarification or add additional context in comments.

Comments

1
foreach($array2 as $syn3)

$syn3 here has been changed to the first element of $array2

Use another name.

1 Comment

Surely, renaming wouldn't work. Do you mean renaming inside the for each loop?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.