0

This is my code:

$xml2  = (array) simplexml_load_string($xml_file);

Using print_r this is my array:

 Array
(
  [program] => Array
        (
        [0] => SimpleXMLElement Object
        (
            [date] => asgasg sgasgasg
            [start_time] => asdg asg
            [leadtext] => as asdgsagsdgasgasgd
            [name] => as gsadgasg
            [bline] => sag asdg
            [synopsis] => asg asga sdg
            [url] => asg sdgasgasg
        )

        [1] => SimpleXMLElement Object
        (
            [date] => sgasgasg1
            [start_time] => asg1
            [leadtext] => as1
            [name] => gsadgasg1
            [bline] => asdg1
            [synopsis] => sdg1
            [url] =>sdgasgasg1
        )

        )
)

how can I do a echo to get the contents of [date] from the 2nd SimpleXMLElement (which is sgasgasg1 in the above example)

hakre
  • 193,403
  • 52
  • 435
  • 836
Ryan
  • 9,821
  • 22
  • 66
  • 101

2 Answers2

2

Use

foreach($xml2['program'] as $key=>$value) {

   echo $value->date;

}

As you told in your comment only

echo $xml2['program'][1]->date;
GBD
  • 15,847
  • 2
  • 46
  • 50
  • No, I only want to get that specific value once, for example: "The date is".$date_here – Ryan Oct 31 '12 at 16:45
2

You can do it like this:

echo $xml2['program'][1]->date;
Nelson
  • 49,283
  • 8
  • 68
  • 81