简体   繁体   中英

How i can access an object in php

Please see this code below:

for($i=0;$i<=count($s->channel);$i++){
    echo "--->".$ChannelName = $s->channel[$i]->{'display-name'};
    $arrChannelName[] = $ChannelName;
}

print_r($arrChannelName);

This return me output as Object instead of an array as:

Array
(
    [0] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [lang] => dk
                )

            [0] => DR1 DK
        )

)

Anybody please help...!!!

Regards

Actually, you have an array of objects of type SimpleXMLElement. Your array has a length of one and key 0 is mapped to the SimpleXMLElement.

$arr = array("somearray" => array(6 => 5, 13 => 9, "a" => 42));

echo $arr["somearray"][6];    // 5

Like this , you can read that object array.

Or

You can use stdclass

http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM