이것은 단순한 것입니다. 나는 simplexml 객체에 배열을 가지고있다. 배열에 변수를 할당하려고하면 배열의 첫 번째 인덱스 만 할당됩니다. 전체 배열을 할당하려면 어떻게해야합니까? 이것은 내 코드입니다.변수를 배열에 할당 할 때 문제가 발생했습니다.
$xml = simplexml_load_string(FlickrUtils::getMyPhotos("flickr.photos.search", $_SESSION['token']));
$photosArray = $xml->photos;
//$photosArray = $xml->photos->photo;
//echo gettype($photosArray);
print_r($photosArray);
이것은 print_r ($ photosArray)의 결과입니다.
SimpleXMLElement Object
(
[@attributes] => Array
(
[page] => 1
[pages] => 1
[perpage] => 100
[total] => 4
)
[photo] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 5335626037
[owner] => [email protected]
[secret] => bd66f06b49
[server] => 5210
[farm] => 6
[title] => 1
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 5336238676
[owner] => [email protected]
[secret] => 898dffa011
[server] => 5286
[farm] => 6
[title] => 2
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 5335625381
[owner] => [email protected]
[secret] => 60a0c84597
[server] => 5126
[farm] => 6
[title] => 4
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 5335625195
[owner] => [email protected]
[secret] => 49348c1e8b
[server] => 5126
[farm] => 6
[title] => 3
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
)
)
감사합니다.
처럼, 당신은 배열에 SimpleXML을 개체의 목록을 시전 할 수
children()
에 사용 할 수 있습니다 이유'[포토] => 배열 '은 배열을 나타내지 않습니다. 그럼에도 불구하고 가장 간단하고 유용한 대답은 +1 할 수 있습니다. –
@Samuel Herzog 그것은 객체 $ xml-> photos;의 속성이지만, 여러분이 맞습니다. 그것은 배열입니다. 그러나 잘못된 곳에서. – phihag