SimpleXMLElement Object and hidden child elements - php

I'm asking for explanation of the following behavior behind the scene in PHP.
I have a SimpleXMLElement Object that I print_r(); Here is the result:
Array
(
[Shipments] => SimpleXMLElement Object
(
[Shipment] => SimpleXMLElement Object
(
[Rates] => SimpleXMLElement Object
(
[Rate] => SimpleXMLElement Object
(
[Service] => C
[ServiceCharge] => 10.18
[ServiceChargeDetails] => SimpleXMLElement Object
(
[BaseCharge] => 8.33
[CODCharge] => 0
[DeclaredCharge] => 0
[AdditionalCharges] => 1.85
[SaturdayCharge] => 0
)
[FuelCharge] => 0
[TotalCharge] => 10.18
[BilledWeight] => 6
[TransitDays] => 1
[ExpectedDeliveryDate] => 20160121
[CommitTime] => 17:00:00
[RateZone] => 2
[GlobalRate] => 10.66
)
)
[UID] => ID1
[Delzip] => 95126
[PUZip] => 95035
[Declared] => 100
[Residential] => true
[COD] => 0
[SaturdayDel] => false
[Weight] => 2
[DIM] => SimpleXMLElement Object
(
[Length] => 10
[Width] => 12
[Height] => 13
)
[Error] => SimpleXMLElement Object
(
)
)
[Error] => SimpleXMLElement Object
(
)
)
)
Please take a look at the "TotalCharge". It doesn't seem to have any child elements however when I do the following:
print_r($response['Shipments']->Shipment->Rates->Rate->TotalCharge);
Here is what I get:
SimpleXMLElement Object
(
[0] => 10.18
)
I'm trying to understand how did the [0] get there and why the initial print_r didn't show it?
Thanks!

Related

Need to access array values from array in PHP

I got array value from API.
model\Quote Object
(
[quote_reference:protected] => 12345
[proposals:protected] => model\Proposals Object
(
[proposal:protected] => Array
(
[0] => model\Proposal Object
(
[id:protected] => prp_3453453453sdfsd
[fees_included:protected] => 1
[charged_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 105.00
)
[credited_amount:protected] => model\Amount Object
(
[currency:protected] => MAD
[amount:protected] => 1000.00
)
[principal_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 100.00
)
[expiration_date:protected] => DateTime Object
(
[date] => 2016-04-07 02:12:55.682000
[timezone_type] => 1
[timezone] => -05:00
)
[destination_service_tag:protected] =>
[corridor_tag:protected] =>
[resource_type:protected] => proposal
[additional_data_list:protected] => model\AdditionalDataList Object
(
[data:protected] => model\Data Object
(
[data_field:protected] => Array
(
[0] => model\DataField Object
(
[name:protected] => 811
[value:protected] => 123
)
[1] => model\DataField Object
(
[name:protected] => 851
[value:protected] => 456
)
)
)
[item_count:protected] => 2
[resource_type:protected] => list
)
[wholesale_fx_rate:protected] =>
)
[1] => model\Proposal Object
(
[id:protected] => prp_456sgdfgsdfg [fees_included:protected] => 1
[charged_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 100.00
)
[credited_amount:protected] => model\Amount Object
(
[currency:protected] => MAD
[amount:protected] => 950.00
)
[principal_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 100.00
)
[expiration_date:protected] => DateTime Object
(
[date] => 2016-04-07 02:22:55.682000
[timezone_type] => 1
[timezone] => -05:00
)
[destination_service_tag:protected] =>
[corridor_tag:protected] =>
[resource_type:protected] => proposal
[additional_data_list:protected] => model\AdditionalDataList Object
(
[data:protected] => model\Data Object
(
[data_field:protected] => Array
(
[0] => model\DataField Object
(
[name:protected] => 811
[value:protected] => 123
)
[1] => model\DataField Object
(
[name:protected] => 851
[value:protected] => 456
)
)
)
[item_count:protected] => 2
[resource_type:protected] => list
)
[wholesale_fx_rate:protected] =>
)
)
)
)
I need to access both proposal array values at 0 and 1 index position.
I Tried:
$arrayobject->proposals->proposal[0];
Getting error:
Fatal error: Cannot access protected property model\Quote::$proposal
Any idea or help would be appreciated.
Thanks!

Using a PHP for loop to display repeating nodes from a huge external XML feed

I've been at this problem for a week or so and haven't found any information in already exiting questions that have lead to a solution. I am pulling in a very large XML file from a company (it's a MITS Feed) that easily tops a million lines of output. I unfortunately can not give the location of this file due to legal reasons, but i'll explain what I'm trying to do and maybe you all can help me put this issue to rest.
I'm calling in the file as such:
<?php
$xml=simplexml_load_file("location-of-file/feed.xml");
?>
After this I want to run through and pull out pieces of information for each property. Here is the exact schema we are using -
http://www.mitsproject.com/Content/ServeFile.cfm?FileID=4075
I've tried importing this as a DOMDocument and traversing through the XML that way, but have had no luck. Possibly just an example of how to pull all of the Property nodes in a PHP for loop would be the bomb. Thank you in advance.
P.S. I know the file is at least being grabbed, because when I run -
<?php
$xml = simplexml_load_file("location-of-file/feed.xml", null, LIBXML_NOCDATA);
print_r($xml);
?>
I am getting an insanely large output.
UPDATE:
Here is an example of one 'Property' as a SimpleXMLElement, maybe this will help -
[111] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
)
[PropertyID] => SimpleXMLElement Object
(
[Identification] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
[OrganizationName] => rentershq
[IDType] => property
)
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 1a47b013fa94796a8973a23cc8b01192ba603460
[OrganizationName] => rentershq
[IDType] => Company
)
)
)
[MarketingName] => Clean Older Unit
[WebSite] => http://rentershq.appfolio.com/listings/listings/56bce392-b9fb-4290-97bc-900b9ebf9a1e
[Address] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AddressType] => property
)
[Description] => Address of Available Listing
[AddressLine1] => 2850 PIONEER DRIVE - 17
[City] => REDDING
[State] => CA
[PostalCode] => 96001
[Country] => US
)
[Phone] => SimpleXMLElement Object
(
[#attributes] => Array
(
[PhoneType] => office
)
[PhoneNumber] => (530) 722-0800
)
[Email] => james#rentershq.com
)
[ILS_Identification] => SimpleXMLElement Object
(
[#attributes] => Array
(
[ILS_IdentificationType] => Apartment
[RentalType] => Market Rate
)
[Latitude] => 40.5873599
[Longitude] => -122.41376
[LastUpdate] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Month] => 12
[Day] => 4
[Year] => 2013
)
)
)
[Information] => SimpleXMLElement Object
(
[StructureType] => Standard
[UnitCount] => 1
[ShortDescription] => Clean Older Unit
[LongDescription] => Please drive by property. Please contact onsite manager Joe Skeen to view inside of unit. 530-255-8375
[Rents] => SimpleXMLElement Object
(
[StandardRent] => 500.00
)
[PropertyAvailabilityURL] => http://rentershq.appfolio.com/listings/listings/56bce392-b9fb-4290-97bc-900b9ebf9a1e
)
[Fee] => SimpleXMLElement Object
(
[ProrateType] => Standard
[LateType] => Standard
[LatePercent] => 0
[LateMinFee] => 0
[LateFeePerDay] => 0
[NonRefundableHoldFee] => 0
[AdminFee] => 0
[ApplicationFee] => 15.00
[BrokerFee] => 0
)
[Deposit] => SimpleXMLElement Object
(
[#attributes] => Array
(
[DepositType] => Security Deposit
)
[Amount] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmountType] => Actual
)
[ValueRange] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Exact] => 700.00
[Currency] => USD
)
)
)
)
[Policy] => SimpleXMLElement Object
(
[Pet] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Allowed] => false
)
)
)
[Phase] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
)
[Name] => SimpleXMLElement Object
(
)
[Description] => SimpleXMLElement Object
(
)
[UnitCount] => 1
[RentableUnits] => 1
[TotalSquareFeet] => 625
[RentableSquareFeet] => 625
)
[Building] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
)
[Name] => SimpleXMLElement Object
(
)
[Description] => SimpleXMLElement Object
(
)
[UnitCount] => 1
[SquareFeet] => 625
)
[Floorplan] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
)
[Name] => SimpleXMLElement Object
(
)
[UnitCount] => 1
[Room] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[RoomType] => Bedroom
)
[Count] => 2
[Comment] => SimpleXMLElement Object
(
)
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[RoomType] => Bathroom
)
[Count] => 1
[Comment] => SimpleXMLElement Object
(
)
)
)
[SquareFeet] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Min] => 625
[Max] => 625
)
)
[MarketRent] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Min] => 500
[Max] => 500
)
)
[EffectiveRent] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Min] => 500
[Max] => 500
)
)
)
[ILS_Unit] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
)
[Units] => SimpleXMLElement Object
(
[Unit] => SimpleXMLElement Object
(
[Identification] => SimpleXMLElement Object
(
[#attributes] => Array
(
[IDValue] => 56bce392-b9fb-4290-97bc-900b9ebf9a1e
[OrganizationName] => RentersHQ
)
)
[MarketingName] => Clean Older Unit
[UnitBedrooms] => 2
[UnitBathrooms] => 1.0
[MinSquareFeet] => 625
[MaxSquareFeet] => 625
[SquareFootType] => internal
[UnitRent] => 500.00
[MarketRent] => 500.00
[Address] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AddressType] => property
)
[AddressLine1] => 2850 PIONEER DRIVE - 17
[City] => REDDING
[PostalCode] => 96001
[Country] => US
)
)
)
[Availability] => SimpleXMLElement Object
(
[VacateDate] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Month] => 7
[Day] => 26
[Year] => 2013
)
)
[VacancyClass] => Unoccupied
[MadeReadyDate] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Month] => 7
[Day] => 26
[Year] => 2013
)
)
)
[Amenity] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Ground Level Apartment
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => HUD Considered
)
[2] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Month-to-Month Lease
)
[3] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Credit Check Required
)
[4] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Stove
)
[5] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Window Coverings
)
[6] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Carpet
)
[Description] => Tille and Carpet
)
[7] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Off Street Parking
)
[8] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Dryer
)
[Description] => Coin-Op Washer / Dryer
)
[9] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Washer
)
[Description] => Coin-Op Washer / Dryer
)
[10] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Refrigerator
)
[Description] => Refrigerator
)
[11] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => DishWasher
)
[Description] => Dishwasher
)
[12] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Washer
)
[Description] => Dishwasher
)
[13] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Disposal
)
[Description] => Garbage Disposal
)
[14] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Heat
)
[Description] => Elec. Heating
)
[15] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Window Cooler
)
[16] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Dog Not Allowed
)
[17] => SimpleXMLElement Object
(
[#attributes] => Array
(
[AmenityType] => Other
)
[Description] => Cat Not Allowed
)
)
)
[File] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Active] => true
[FileID] => 809492874
)
[FileType] => Photo
[Description] => Unit Photo
[Name] => SimpleXMLElement Object
(
)
[Caption] => SimpleXMLElement Object
(
)
[Format] => image/jpeg
[Src] => http://pa.cdn.appfolio.com/rentershq/images/8ed6dbf4-36cf-47e4-b519-7783bea727dc/medium.jpg
[Width] => 1280
[Height] => 960
[Rank] => 1
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Active] => true
[FileID] => 809492885
)
[FileType] => Photo
[Description] => Unit Photo
[Name] => SimpleXMLElement Object
(
)
[Caption] => SimpleXMLElement Object
(
)
[Format] => image/jpeg
[Src] => http://pa.cdn.appfolio.com/rentershq/images/9b6b35e7-0ca1-4c20-a396-4be6fb21bf80/medium.jpg
[Width] => 1280
[Height] => 960
[Rank] => 2
)
[2] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Active] => true
[FileID] => 809492887
)
[FileType] => Photo
[Description] => Unit Photo
[Name] => SimpleXMLElement Object
(
)
[Caption] => SimpleXMLElement Object
(
)
[Format] => image/jpeg
[Src] => http://pa.cdn.appfolio.com/rentershq/images/c6ab69e3-0787-4221-893d-fbd982c2a3bd/medium.jpg
[Width] => 1280
[Height] => 960
[Rank] => 3
)
[3] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Active] => true
[FileID] => 809492889
)
[FileType] => Photo
[Description] => Unit Photo
[Name] => SimpleXMLElement Object
(
)
[Caption] => SimpleXMLElement Object
(
)
[Format] => image/jpeg
[Src] => http://pa.cdn.appfolio.com/rentershq/images/6ac14176-73c3-452b-80ae-b41820887c73/medium.jpg
[Width] => 1280
[Height] => 960
[Rank] => 4
)
[4] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Active] => true
[FileID] => 809492892
)
[FileType] => Photo
[Description] => Unit Photo
[Name] => SimpleXMLElement Object
(
)
[Caption] => SimpleXMLElement Object
(
)
[Format] => image/jpeg
[Src] => http://pa.cdn.appfolio.com/rentershq/images/252a2ae1-66ea-471d-8cf1-48e795add81d/medium.jpg
[Width] => 960
[Height] => 1280
[Rank] => 5
)
[5] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Active] => true
[FileID] => 809492895
)
[FileType] => Photo
[Description] => Unit Photo
[Name] => SimpleXMLElement Object
(
)
[Caption] => SimpleXMLElement Object
(
)
[Format] => image/jpeg
[Src] => http://pa.cdn.appfolio.com/rentershq/images/b93c93f6-b571-4a33-a4e3-e0ac663679bc/medium.jpg
[Width] => 1280
[Height] => 960
[Rank] => 6
)
)
)
try outputting the feed using
echo '<pre>';
print_r($feed);
echo '</pre>';
This should give you a much 'prettier' view of the scheme and what nodes are/aren't accessible!
I'd recommend something similar to this:
$xml = simplexml_load_file("location-of-file/feed.xml", null, LIBXML_NOCDATA);
foreach($xml as $key => $item){
// to select an element do something like this
$item->WebSite;
}
however please note that $item is a copy of the array $xml so to manipulate this object you will need to change $item to &$item or you will need to manipulate the actual value as such in your loop
$test = $item->WebSite;
//do something to $test
$xml->$key->WebSite = $test;
if however you are building a new array/xml document you don't need to worry about this issue
Update:
I have tested this on an example feed and you should be able to get this too work with a little editing
header("Content-Type: application/xml; charset=utf-8");
$xml = simplexml_load_file("test.xml", null, LIBXML_NOCDATA);
$values = array("Belgian Waffles","French Toast");
$new = new SimpleXMLElement("<tester></tester>");
foreach($xml->food as $item){
if(in_array($item->name,$values)){
$type = $new->addChild('type');
$movie = $type->addChild('movie');
$movie->addChild('price', $item->price);
}else{
}
}
echo $new->asXML();
basically give this ago, edit it to use the right nodes and build the feed right for you then this should work. the asXML() has a optional parameter you can pass in to write the file
so changing echo $new->asXML(); to $new->asXML("test.xml"); will instead write the file to test.xml instead of outputting the data. if you do save it make sure you get rid of header("Content-Type: application/xml; charset=utf-8");

How to access the properties of an XML string converted to an object

I used a web service that returns the result in XML format. The method simplexml_load_string() was used to convert it to an object like this:
$xml = simplexml_load_string($result[$webresult]);
Below is a sample display using
print_r($xml) :
SimpleXMLElement Object ( [record] => SimpleXMLElement Object ( [txnref] => 6113229211825720 [channel] => mastercard [amount] => 3000.00 [payment_date] => 8/17/2013 9:18:25 PM [payment_status] => successful [field_values] => SimpleXMLElement Object ( [field_values] => SimpleXMLElement Object ( [field] => Array ( [0] => SimpleXMLElement Object ( [names] => Frank [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [1] => SimpleXMLElement Object ( [amount] => 3000 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [2] => SimpleXMLElement Object ( [currency] => NGN [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [3] => SimpleXMLElement Object ( [email_address] => chibuzo.henry#gmail.com [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [4] => SimpleXMLElement Object ( [phone_number] => 08035653468 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [5] => SimpleXMLElement Object ( [merch_txnref] => 134 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) ) ) ) [payment_status_description] => Transaction Successful - Approved ) )
However, when I try to access the object $xml, this way:
$xml->amount;
it doesn't return any result. How do I access the properties of the object correctly?
The amount property is in a record object so try $xml->record->amount;
Amount is in Record object so use $xml->record->amount;
First you print one web service response one necessary step keep in your mind
use echo "<pre>";
then you print your array
For eg:
echo "<pre>";
print_r($xml);
Then only you see the array format clearly

How to loop through a SimpleXMLElement object in Php?

How to loop through a SimpleXMLElement object?
This is what I have:
I tried in many ways to iterate, but no success:
SimpleXMLElement Object
(
[products] => SimpleXMLElement Object
(
[product] => Array
(
[0] => SimpleXMLElement Object
(
[product_name] => PROD1
[price] => 100.2
[has_special_price] => true
[special_price_desc] => DESC SPECIAL PRICE
[id_product_remote] => CUSTOMID-01
[decimals] => 0
[category_key] => 1
[packaging_key] => 2
[stock_type_key] => 1
)
[1] => SimpleXMLElement Object
(
[product_name] => PROD2
[price] => 200.2
[has_special_price] => false
[special_price_desc] => DEsdSC SPECIAL PRICE
[id_product_remote] => CUSTOMID-02
[decimals] => 0
[category_key] => 1
[packaging_key] => 2
[stock_type_key] => 1
)
)
)
[products_client] => SimpleXMLElement Object
(
[product_client] => Array
(
[0] => SimpleXMLElement Object
(
[id_client_remote] => CUSTOMCLIENT-01
[id_product_remote] => CUSTOMID-01
[custom_price] => 0
)
[1] => SimpleXMLElement Object
(
[id_client_remote] => CUSTOMCLIENT-02
[id_product_remote] => CUSTOMID-02
[custom_price] => 1
)
)
)
)
What have you tried?
foreach($xml_object->products->product as $key => $product){
echo $product->product_name;
}
Try doing:
foreach($yourVar->products->product as $key => $val) {
echo $val->product_name; /// and so on
}

problem assigning array to variable

I'm sure this is a simple one. I have an array in a simplexml object. When I try to assign the array to a variable, it only assigns the first index of the array. How can I get it to assign the whole array. This is my code.
$xml = simplexml_load_string(FlickrUtils::getMyPhotos("flickr.photos.search", $_SESSION['token']));
$photosArray = $xml->photos;
//$photosArray = $xml->photos->photo;
//echo gettype($photosArray);
print_r($photosArray);
This is the result of the 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] => 57991585#N02
[secret] => bd66f06b49
[server] => 5210
[farm] => 6
[title] => 1
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[id] => 5336238676
[owner] => 57991585#N02
[secret] => 898dffa011
[server] => 5286
[farm] => 6
[title] => 2
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
[2] => SimpleXMLElement Object
(
[#attributes] => Array
(
[id] => 5335625381
[owner] => 57991585#N02
[secret] => 60a0c84597
[server] => 5126
[farm] => 6
[title] => 4
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
[3] => SimpleXMLElement Object
(
[#attributes] => Array
(
[id] => 5335625195
[owner] => 57991585#N02
[secret] => 49348c1e8b
[server] => 5126
[farm] => 6
[title] => 3
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
)
)
)
Thanks for youe help!
I fail to see an array in your example. However, $xml is traversable, so you probably mean that. $xml->photos selects only the first photo element though. You are probably looking for
$photosArray = $xml->xpath('//photo');
which indeed returns an array.
In order to return all photo, can make used on children()
You can cast the list of simplexml objects into array, like
$photosArray = (array)$xml->children();
/* or retain the simplexml object */
$photosArray = $xml->children();

Categories