stdClass Object
(
[id_pro_alert] => 155
[User_Id] => 252
[Pro_Id] => 329
[alertmethod] => daily
[Alertname] => xcxv
[name] => cyriac
[email] => cyriac#tewve.com
[date] => 2016-21-10 09:20:26
[mobile] =>
[comments] =>
[Alert_Id] => 329
[Prop_Purpose] => lease
[Min_Area] => 500
[Max_Area] => 1000
[Area_unit] => Sq.ft
[Min_cost] => 1000
[Max_cost] => 10000
[City] => kochi
[Create_Date] => 2016-10-17 12:59:14
[Update_Date] => 2016-10-17 12:59:14
[Status] => Active
[0] => stdClass Object
(
[Prop_type] => Agricultural Land
)
[1] => stdClass Object
(
[Prop_type] => Office in IT park
)
[2] => stdClass Object
(
[Prop_type] => Business center
)
)
How to get Prop_type value from stdclass
Check this, You can access all Prop_type's
foreach($data as $key=>$row){
if (is_int($key)) {
echo $row->Prop_type;
}
}
Create array of Prop_type's
$propData =array();
foreach($data as $key=>$row){
if (is_int($key)) {
$propData[] = $row->Prop_type;
}
}
echo $array->0->Prop_type;
Related
I am getting below json data thru Shiprocket API. Now I want to extract value of below variables in PHP code from this json.
I have tried to use json_decode but it did not work and show null value:
$data = json_decode($json);
$sr_status = $data['shipment_status'];
Please suggest the code to retrieve below variables value.
shipment_status , awb_code , courier_company_id
Array
(
[0] => stdClass Object
(
[tracking_data] => stdClass Object
(
[track_status] => 1
[shipment_status] => 7
[shipment_track] => Array
(
[0] => stdClass Object
(
[id] => 180339484
[awb_code] => 11150911492
[courier_company_id] => 55
[shipment_id] => 1711169662
[order_id] => 233223781187
[pickup_date] => 2023-01-11 03:02:00
[delivered_date] => 2023-01-16 12:22:00
[weight] => 0.25
[packages] => 1
[current_status] => Delivered
[delivered_to] => Solapur
[destination] => Solapur
[consignee_name] => ABC
[origin] => Ludhiana
[courier_agent_details] =>
[edd] =>
)
)
[shipment_track_activities] => Array
(
[0] => stdClass Object
(
[date] => 2023-01-16 12:22:00
[status] => 000-T-DL
[activity] => SHIPMENT DELIVERED
[location] => SOLAPUR
[sr-status] => 7
[sr-status-label] => DELIVERED
)
[1] => stdClass Object
(
[date] => 2023-01-16 11:34:00
[status] => 002-S-UD
[activity] => SHIPMENT OUTSCAN
[location] => SOLAPUR
[sr-status] => 17
[sr-status-label] => OUT FOR DELIVERY
)
)
[track_url] => https://shiprocket.co//tracking/11150911492
[etd] => 2023-01-14 17:02:00
[qc_response] => stdClass Object
(
[qc_image] =>
[qc_failed_reason] =>
)
)
)
)
you can try this:
$array = ...; // Your array here
$data= json_decode($array);
$shipment_status = $data[0]->tracking_data->shipment_status;
$awb_code = $data[0]->tracking_data->shipment_track[0]->awb_code;
$courier_company_id = $data[0]->tracking_data->shipment_track[0]->courier_company_id;
Or use $data = json_decode($json,true); which return an array where you can use
foreach($data as $val) {
$shipment_status = $val['tracking_data']['shipment_status'];
foreach ($val['shipment_track'] as $value) {
$awb_code = $value['awb_code'];
$courier_company_id = $value['courier_company_id'];
}
}
I want to add elements to an array with a condition, but with this code the $ready array only work with the first value of array. what did i miss ?
$data['garduinduk'] :
Array ( [0] => stdClass Object (
[id] => 1
[id_app] => 2
[id_basecamp] => 1
[nama] => GI BOGOR BARU
[room] =>
)
[1] => stdClass Object (
[id] => 2
[id_app] => 2
[id_basecamp] => 1
[nama] => GI CIAWI BARU
[room] =>
)
[2] => stdClass Object (
[id] => 3
[id_app] => 2
[id_basecamp] => 1
[nama] => GI CIAWI
[room] =>
)
$ready :
Array ( [0] => stdClass Object (
[lokasi] => 1
[berlaku_dari] =>
[berlaku_sampai] => 0000-00-00
[status] => On_progress
[file] =>
)
[1] => stdClass Object (
[lokasi] => 16
[berlaku_dari] =>
[berlaku_sampai] => 0000-00-00
[status] => On_progress
[file] =>
)
[2] => stdClass Object (
[lokasi] => 2
[berlaku_dari] =>
[berlaku_sampai] => 0000-00-00
[status] => On_progress
[file] => /assets/files/155bd035e88358b.PNG
)
[3] => stdClass Object (
[lokasi] => 2
[berlaku_dari] => 2019-02-27
[berlaku_sampai] => 2019-02-28
[status] => Selesai
[file] => /assets/files/215c76691f12ae9.pdf
)
)
Code :
foreach ($data['garduinduk'] as $key => $gi){
foreach ($ready as $rdy){
if ($rdy->lokasi == $gi->id){
if ($rdy->status == 'On_progress'){
$gi->berlaku_dari = 'ON PROGRESS';
$gi->berlaku_sampai = 'ON PROGRESS';
$gi->file = 'ON PROGRESS';
}else{
$gi->berlaku_dari = $rdy->berlaku_dari;
$gi->berlaku_sampai = $rdy->berlaku_sampai;
$gi->file = $rdy->file;
}
}else{
$gi->berlaku_dari = '';
$gi->berlaku_sampai = '';
$gi->file = '';
}
}
}
Use reference on $gi
foreach ($data['garduinduk'] as $key => &$gi){
or use
$data['garduinduk'][$key]->
instead of
$gi->
I have json return string like given below. I want to extract cancellation Policy list of objects like cutoff Time and refund In Percentage. I tried using for-loop but it didn't help me. Can you please help me on extracting this.
Array (
[apiStatus] => Array ( [success] => 1 [message] => SUCCESS ) <br>
[apiAvailableBuses] => Array ( <br>
[0] => Array ( [droppingPoints] => [availableSeats] => 41 <br>[partialCancellationAllowed] => [arrivalTime] => 08:00 AM <br>
[cancellationPolicy] => [<br>
{"cutoffTime":"1","refundInPercentage":"10"},<br>
{"cutoffTime":"2","refundInPercentage":"50"},<br>
{"cutoffTime":"4","refundInPercentage":"90"}<br>
] <br>
[boardingPoints] => Array ( [0] => Array ( [time] => 09:00PM [location] => Ameerpet,|Jeans Corner 9687452130 [id] => 6 ) [1] => Array ( [time] => 09:15PM [location] => S.R Nagar,S.R Nagar [id] => 2224 ) [2] => Array ( [time] => 09:10PM [location] => Kondapur,Toyota Show room [id] => 2244 ) ) [operatorName] => Deepak Travels [departureTime] => 9:00 PM [mTicketAllowed] => [idProofRequired] => [serviceId] => 6622 [fare] => 800 [busType] => 2+1 Hi-Tech Non A/c [routeScheduleId] => 6622 [commPCT] => 0 [operatorId] => 213 [inventoryType] => 0 ) <br>
[1] => Array ( [droppingPoints] => [availableSeats] => 41 [partialCancellationAllowed] => [arrivalTime] => 07:00 AM <br>
[cancellationPolicy] => [<br>
{"cutoffTime":"1","refundInPercentage":"10"},<br>
{"cutoffTime":"2","refundInPercentage":"50"},<br>
{"cutoffTime":"4","refundInPercentage":"90"}<br>
] <br>
[boardingPoints] => Array ( [0] => Array ( [time] => 09:10PM [location] => Ameerpet,|Jeans Corner [id] => 6 ) [1] => Array ( [time] => 09:00PM [location] => S.R Nagar,S.R Nagar [id] => 2224 ) [2] => Array ( [time] => 08:30PM [location] => KUKATPALLY,JNTU [id] => 2230 ) ) [operatorName] => Dhanunjayabus [departureTime] => 9:00 PM [mTicketAllowed] => [idProofRequired] => [serviceId] => 6743 [fare] => 900 [busType] => VOLVO [routeScheduleId] => 6743 [commPCT] => 0 [operatorId] => 233 [inventoryType] => 0 )
)
)
Use a foreach() for it like so:
foreach ($your_response['apiAvailableBuses'] as $el) {
$cancellationPolicy[] = $el['cancellationPolicy'];
}
Try this:
foreach($data['apiStatus']['apiAvailableBuses'] as $item) {
foreach($item['cancellationPolicy'] as $key => $json) {
$jsonDecoded = json_decode($json, true);
// And you will have access to the data like this
// $jsonDecoded['cutoffTime'];
// $jsonDecoded['refundInPercentage'];
}
}
$response = json_decode($apiResponse);
$cancellationPolicies = [];
foreach ($response->apiAvailableBuses as $availableBus) {
$cancellationPolicies[] = $availableBus['cancellationPolicy'];
// if you want to display something you can simply do it like this;
echo $availableBus['cancellationPolicy']->cutoffTime;
}
PROGRESS: Almost there... Need help on the last bit!!!
$users = $client->getAccounts();
$num = count($users);
for ( $x=0; $x < $num; $x++){
foreach($users[$x] as $y => $y_value) {
if($y_value == iLy){
print_r($y);
echo '<br>';
print_r($x);
echo '<br>';
print_r($user[$x]["id"]);
}
}
}
Above is the latest bit of code I have written and I have been to locate the array value or the array I am looking for by search by name. print_r($user[$x]["id"]);
Results in:
Warning: Illegal string offset 'id' in /home/examplesite/BLANK.com/CBapi.php on line 37
I used this simplification to discover the logic for my solution:
This works
<?php
$age = array (array("name"=>"iLy", "id"=>"37", "balance"=>"43"),
array("name"=>"jim", "id"=>"67", "balance"=>"47"));
echo $age[0]['id'];
$num = count($age);
for ( $x=0; $x < $num; $x++){
foreach($age[$x] as $y => $y_value) {
if($y_value == 43){
print_r($y);
echo '<br>';
print_r($x);
echo '<br>';
print_r($age[$x]["id"]);
}
}
}
?>
I believe I am just calling the wrong Key Name.
++++++++++++++++++++++ Original Post Below ++++++++++++++++++++++
Current code:
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$configuration->setApiUrl(Configuration::SANDBOX_API_URL);
$client = Client::create($configuration);
$users = $client->getAccounts();
I have been struggling with this for four days now... I used function below and it returns an object which contains an array of objects. My goal is to search through the collection of objects for a key and value, (For example to search the name of a current user:$currentuser = 'iLy'; $user = $currentuser; Then I could identify the array value, which would be $users[2] for our example 'iLy' to search the key value 'id', to get the $accountId.
Ideally I could search 'name' => iLy and have it return the 'id' => 'xxxxxxx' in that same array.
When I create accounts this is the only way I have been able to figure out how to get the accountID, and I haven't found any other API calls to get the account by name. I have only been able to isolate one object using $users[2]. I know this may be a repeat post, but I haven't been able to make any of the other solutions work.
PHP - find entry by object property from a array of objects , Array of PHP Objects
Maybe I am using the wrong solutions or applying them wrong. Any help would be greatly appreciated!
public function getAccounts(array $params = [])
{
return $this->getAndMapCollection('/v2/accounts',$params,'toAccounts');
}
Returns this:
Coinbase\\Wallet\\Resource\\ResourceCollection Object (
[previousUri:Coinbase\\Wallet\\Resource\\ResourceCollection:private] =>
[nextUri:Coinbase\\Wallet\\Resource\\ResourceCollection:private] =>
[resources:Coinbase\\Wallet\\Resource\\ResourceCollection:private] => Array (
[0] => Coinbase\\Wallet\\Resource\\Account Object (
[name:Coinbase\\Wallet\\Resource\\Account:private] => Jennaod3
[primary:Coinbase\\Wallet\\Resource\\Account:private] =>
[type:Coinbase\\Wallet\\Resource\\Account:private] => wallet
[currency:Coinbase\\Wallet\\Resource\\Account:private] => BTC
[balance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.00000000
[currency:Coinbase\\Wallet\\Value\\Money:private] => BTC
)
[nativeBalance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.00
[currency:Coinbase\\Wallet\\Value\\Money:private] => USD
)
[createdAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-24 04:55:41.000000
[timezone_type] => 2
[timezone] => Z
)
[updatedAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-24 04:55:41.000000
[timezone_type] => 2
[timezone] => Z
)
[id:Coinbase\\Wallet\\Resource\\Resource:private] => 0d41fc45-0a53-58cb-9931-c9a33f520963
[resource:Coinbase\\Wallet\\Resource\\Resource:private] => account
[resourcePath:Coinbase\\Wallet\\Resource\\Resource:private] => /v2/accounts/0d41fc45-0a53-58cb-9931-c9a33f520963
[rawData:Coinbase\\Wallet\\Resource\\Resource:private] => Array (
[id] => 0d41fc45-0a53-58cb-9931-c9a33f520963
[name] => Jennaod3
[primary] =>
[type] => wallet
[currency] => BTC
[balance] => Array (
[amount] => 0.00000000
[currency] => BTC
)
[native_balance] => Array (
[amount] => 0.00
[currency] => USD
)
[created_at] => 2016-05-24T04:55:41Z
[updated_at] => 2016-05-24T04:55:41Z
[resource] => account
[resource_path] => /v2/accounts/0d41fc45-0a53-58cb-9931-c9a33f520963
)
)
[1] => Coinbase\\Wallet\\Resource\\Account Object (
[name:Coinbase\\Wallet\\Resource\\Account:private] => jenna works to
[primary:Coinbase\\Wallet\\Resource\\Account:private] =>
[type:Coinbase\\Wallet\\Resource\\Account:private] => wallet
[currency:Coinbase\\Wallet\\Resource\\Account:private] => BTC
[balance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.00000000
[currency:Coinbase\\Wallet\\Value\\Money:private] => BTC
)
[nativeBalance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.00
[currency:Coinbase\\Wallet\\Value\\Money:private] => USD
)
[createdAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-22 13:37:16.000000
[timezone_type] => 2
[timezone] => Z
)
[updatedAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-22 13:37:16.000000
[timezone_type] => 2
[timezone] => Z
)
[id:Coinbase\\Wallet\\Resource\\Resource:private] => e7ab48b4-bc76-513a-a78b-6d627f32f848
[resource:Coinbase\\Wallet\\Resource\\Resource:private] => account
[resourcePath:Coinbase\\Wallet\\Resource\\Resource:private] => /v2/accounts/e7ab48b4-bc76-513a-a78b-6d627f32f848
[rawData:Coinbase\\Wallet\\Resource\\Resource:private] => Array (
[id] => e7ab48b4-bc76-513a-a78b-6d627f32f848
[name] => jenna works to
[primary] =>
[type] => wallet
[currency] => BTC
[balance] => Array (
[amount] => 0.00000000
[currency] => BTC
)
[native_balance] => Array (
[amount] => 0.00
[currency] => USD
)
[created_at] => 2016-05-22T13:37:16Z
[updated_at] => 2016-05-22T13:37:16Z
[resource] => account
[resource_path] => /v2/accounts/e7ab48b4-bc76-513a-a78b-6d627f32f848
)
)
[2] => Coinbase\\Wallet\\Resource\\Account Object (
[name:Coinbase\\Wallet\\Resource\\Account:private] => iLy
[primary:Coinbase\\Wallet\\Resource\\Account:private] =>
[type:Coinbase\\Wallet\\Resource\\Account:private] => wallet
[currency:Coinbase\\Wallet\\Resource\\Account:private] => BTC
[balance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.00000000
[currency:Coinbase\\Wallet\\Value\\Money:private] => BTC
)
[nativeBalance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.00
[currency:Coinbase\\Wallet\\Value\\Money:private] => USD
)
[createdAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-22 13:33:36.000000
[timezone_type] => 2
[timezone] => Z
)
[updatedAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-22 13:33:36.000000
[timezone_type] => 2
[timezone] => Z
)
[id:Coinbase\\Wallet\\Resource\\Resource:private] => c95fd701-cf2b-56f7-b438-9a2f0e61b21c
[resource:Coinbase\\Wallet\\Resource\\Resource:private] => account
[resourcePath:Coinbase\\Wallet\\Resource\\Resource:private] => /v2/accounts/c95fd701-cf2b-56f7-b438-9a2f0e61b21c
[rawData:Coinbase\\Wallet\\Resource\\Resource:private] => Array (
[id] => c95fd701-cf2b-56f7-b438-9a2f0e61b21c
[name] => iLy
[primary] =>
[type] => wallet
[currency] => BTC
[balance] => Array (
[amount] => 0.00000000
[currency] => BTC
)
[native_balance] => Array (
[amount] => 0.00
[currency] => USD
)
[created_at] => 2016-05-22T13:33:36Z
[updated_at] => 2016-05-22T13:33:36Z
[resource] => account
[resource_path] => /v2/accounts/c95fd701-cf2b-56f7-b438-9a2f0e61b21c
)
)
[3] => Coinbase\\Wallet\\Resource\\Account Object (
[name:Coinbase\\Wallet\\Resource\\Account:private] => BTC Wallet
[primary:Coinbase\\Wallet\\Resource\\Account:private] => 1
[type:Coinbase\\Wallet\\Resource\\Account:private] => wallet
[currency:Coinbase\\Wallet\\Resource\\Account:private] => BTC
[balance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 0.10000000
[currency:Coinbase\\Wallet\\Value\\Money:private] => BTC
)
[nativeBalance:Coinbase\\Wallet\\Resource\\Account:private] => Coinbase\\Wallet\\Value\\Money Object (
[amount:Coinbase\\Wallet\\Value\\Money:private] => 1000.00
[currency:Coinbase\\Wallet\\Value\\Money:private] => USD
)
[createdAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-21 02:41:13.000000
[timezone_type] => 2
[timezone] => Z
)
[updatedAt:Coinbase\\Wallet\\Resource\\Account:private] => DateTime Object (
[date] => 2016-05-21 02:41:14.000000
[timezone_type] => 2
[timezone] => Z
)
[id:Coinbase\\Wallet\\Resource\\Resource:private] => 0e0dac44-6900-59e9-8183-99b9459d1205
[resource:Coinbase\\Wallet\\Resource\\Resource:private] => account
[resourcePath:Coinbase\\Wallet\\Resource\\Resource:private] => /v2/accounts/0e0dac44-6900-59e9-8183-99b9459d1205
[rawData:Coinbase\\Wallet\\Resource\\Resource:private] => Array (
[id] => 0e0dac44-6900-59e9-8183-99b9459d1205
[name] => BTC Wallet
[primary] => 1
[type] => wallet
[currency] => BTC
[balance] => Array (
[amount] => 0.10000000
[currency] => BTC
)
[native_balance] => Array (
[amount] => 1000.00
[currency] => USD
)
[created_at] => 2016-05-21T02:41:13Z
[updated_at] => 2016-05-21T02:41:14Z
[resource] => account
[resource_path] => /v2/accounts/0e0dac44-6900-59e9-8183-99b9459d1205
)
)
)
)
This was my answer and it isn't pretty. It turns out I had to make some of the variables public in the API resource file, which I'm not sure if that was a good idea, but it achieved my goal using this code:
$users = $client->getAccounts();
$num = count($users);
for ( $x=0; $x < $num; $x++){
foreach($users[$x] as $y => $y_value) {
if($y_value == iLy) {
$bae = $users[$x];
$account_id = '';
foreach ($bae as $k => $k_value) {
$account_id = $k_value;
}
}
}
}
It seems as though all my arrays were objects and the only way I could obtain the values I needed was by using foreach loops.
This question already has answers here:
How to convert XML into array in PHP?
(12 answers)
Closed 7 years ago.
I am working on property site. My requirement is to import property info with its images and amenities and store it in to database. I've an xml array and i want to convert it into php array. I've xml array like this:-
SimpleXMLElement Object
(
[Listing] => Array
(
[0] => SimpleXMLElement Object
(
[count] => 1
[Ad_Type] => Rent
[Unit_Type] => Office
[Unit_Model] => SimpleXMLElement Object
(
)
[Primary_View] => SimpleXMLElement Object
(
)
[Unit_Builtup_Area] => 7593.00
[No_of_Bathroom] => 2
[Property_Title] => Business Center / BANKS offices/ Call Centre Offices
[Web_Remarks] => SimpleXMLElement Object
(
)
[Emirate] => Dubai
[Community] => Sheikh Zayed Road
[Property_Name] => Millennium Plaza
[Property_Ref_No] => AMB-R-1142
[Listing_Agent] => Janette Ceniza
[Listing_Agent_Phone] => 0564843282
[Listing_Date] => 2015-03-26 4:53:51 pm
[Last_Updated] => 2015-07-29 1:44:23 pm
[Bedrooms] => SimpleXMLElement Object
(
)
[Listing_Agent_Email] => consult1#khalidalattar.com
[Price] => 1200000
[Frequency] => per year
[Unit_Reference_No] => AMB-R-1142
[No_of_Rooms] => SimpleXMLElement Object
(
)
[Latitude] => 25.062252
[Longitude] => 55.130672
[unit_measure] => Sq.Ft.
[Featured] => 0
[Images] => SimpleXMLElement Object
(
[image] => Array
(
[0] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_19-1605-6d8e8f3aa6e53b45154eac91e2109ba4.jpg
[1] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_35-1605-660a612b520978e1249c29b7fb591b45.jpg
[2] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_36-1605-01d394a6a096b9a0252b30a10fd59c13.jpg
[3] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_38-1605-80df60708c007c5a85721b89c97836d8.jpg
[4] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_38-1605-1f9ffdde85af52dfc6f3548264c34ce0.jpg
[5] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_44-1605-322badce946a4883abe602bf8c221a93.jpg
[6] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_44-1605-117288432442fd54dae0e68238f39537.jpg
[7] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_54-1605-914e38a1abe6418ea10885b94e4f26de.jpg
[8] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_55-1605-fc756a57f7280678b41b07340e3d1e60.jpg
[9] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_54_55-1605-53eb6e2277f1b19ee40a36660086a20e.jpg
[10] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_58_36-1605-9e54faba2c9f96e31646c0660f3f0153.jpg
)
)
[Facilities] => SimpleXMLElement Object
(
[facility] => Array
(
[0] => Built in wardrobes
[1] => Covered parking
[2] => Public parking
)
)
[company_name] => Amber Real Estate
[Web_Tour] => SimpleXMLElement Object
(
)
[Threesixty_Tour] => SimpleXMLElement Object
(
)
[Audio_Tour] => SimpleXMLElement Object
(
)
[Virtual_Tour] => SimpleXMLElement Object
(
)
[QR_Code] => SimpleXMLElement Object
(
)
[company_logo] => http://crm.propspace.com/application/views/pictures/logos/16051408971828.png
[Parking] => 2
[Strno] => SimpleXMLElement Object
(
)
[PreviewLink] => http://crm.propspace.com/preview/index/14273740230306248/1605/?l_id=1576257622628120
)
)
)
There are multiple entries like this. I'd given first entry for the referrence. For converting this xml to php array I've written the below code:-
function convert_xml($xml){
$arr = array();
foreach($xml->children() as $property){
if(count($property->children()) == 0){
$arr[$property->getName()] = strval($property);
}else{
$arr[$property->getName()][] = xml2array($property);
}
}
return $arr;
}
$xml_Arr = convert_xml($xml);
echo "<pre>"; print_r($xml_Arr); exit;
I m getting the result as php array given below.
Array
(
[Listing] => Array
(
[0] => Array
(
[count] => 1
[Ad_Type] => Rent
[Unit_Type] => Office
[Unit_Model] =>
[Primary_View] =>
[Unit_Builtup_Area] => 7593.00
[No_of_Bathroom] => 2
[Property_Title] => Business Center / BANKS offices/ Call Centre Offices
[Emirate] => Dubai
[Community] => Sheikh Zayed Road
[Property_Name] => Millennium Plaza
[Property_Ref_No] => AMB-R-1142
[Listing_Agent] => Janette Ceniza
[Listing_Agent_Phone] => 0564843282
[Listing_Date] => 2015-03-26 4:53:51 pm
[Last_Updated] => 2015-07-29 1:44:23 pm
[Bedrooms] =>
[Listing_Agent_Email] => consult1#khalidalattar.com
[Price] => 1200000
[Frequency] => per year
[Unit_Reference_No] => AMB-R-1142
[No_of_Rooms] =>
[Latitude] => 25.062252
[Longitude] => 55.130672
[unit_measure] => Sq.Ft.
[Featured] => 0
[Images] => Array
(
[0] => Array
(
[image] => http://crm.propspace.com/watermark?c_id=1605&l_id=1576257622628120&aid=1447092&id=14273740230306248&image=26_03_2015-16_58_36-1605-9e54faba2c9f96e31646c0660f3f0153.jpg
)
)
[Facilities] => Array
(
[0] => Array
(
[facility] => Public parking
)
)
[company_name] => Amber Real Estate
[Web_Tour] =>
[Threesixty_Tour] =>
[Audio_Tour] =>
[Virtual_Tour] =>
[QR_Code] =>
[company_logo] => http://crm.propspace.com/application/views/pictures/logos/16051408971828.png
[Parking] => 2
[Strno] =>
[PreviewLink] => http://crm.propspace.com/preview/index/14273740230306248/1605/?l_id=1576257622628120
)
)
)
There are 10 element inside image array, but it is returning only the last image. I want image array as well in my result.
foreach($xml->children() as $key=>$property){
if(count($property->children()) == 0){
$arr[$property->getName()] = strval($property);
}else{
$arr[$property->getName()][$key] = xml2array($property);
}
}