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
  • 184,866
  • 48
  • 414
  • 792
Ryan
  • 9,383
  • 21
  • 63
  • 97

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,512
  • 2
  • 42
  • 49
  • 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
  • 46,753
  • 8
  • 64
  • 79