how to display an array converted from xml - php

I have an Array which i got after converting from an XML, This XML is coming from amazon seller account. It has got all the orders which are available in my seller account.
Im using Yii 2.0 php framework, Im passing this array to view after converting from XML to array in controller. This is my array..
Array
(
[ListOrdersResult] => Array
(
[CreatedBefore] => 2016-07-11T05:59:05Z
[Orders] => Array
(
[Order] => Array
(
[0] => Array
(
[AmazonOrderId] => 171-4557760-7388350
[PurchaseDate] => 2016-06-01T13:07:46Z
[LastUpdateDate] => 2016-06-03T12:43:26Z
[OrderStatus] => Canceled
[FulfillmentChannel] => MFN
[SalesChannel] => Amazon.in
[ShipServiceLevel] => IN Exp Dom 2
[OrderTotal] => Array
(
[CurrencyCode] => INR
[Amount] => 40.00
)
[NumberOfItemsShipped] => 0
[NumberOfItemsUnshipped] => 0
[PaymentExecutionDetail] => Array
(
)
[MarketplaceId] => A21TJRUUN4KGV
[ShipmentServiceLevelCategory] => Expedited
[ShippedByAmazonTFM] => false
[OrderType] => StandardOrder
[EarliestShipDate] => 2016-06-01T18:30:00Z
[LatestShipDate] => 2016-06-03T18:29:59Z
[IsPrime] => false
[IsPremiumOrder] => false
)
[1] => Array
(
[AmazonOrderId] => 403-4718683-0373128
[PurchaseDate] => 2016-06-03T12:30:20Z
[LastUpdateDate] => 2016-06-03T14:02:13Z
[OrderStatus] => Canceled
[FulfillmentChannel] => MFN
[SalesChannel] => Amazon.in
[ShipServiceLevel] => IN Exp Dom 2
[OrderTotal] => Array
(
[CurrencyCode] => INR
[Amount] => 40.00
)
[NumberOfItemsShipped] => 0
[NumberOfItemsUnshipped] => 0
[PaymentExecutionDetail] => Array
(
)
[MarketplaceId] => A21TJRUUN4KGV
[ShipmentServiceLevelCategory] => Expedited
[ShippedByAmazonTFM] => false
[OrderType] => StandardOrder
[EarliestShipDate] => 2016-06-03T18:30:00Z
[LatestShipDate] => 2016-06-06T18:29:59Z
[IsPrime] => false
[IsPremiumOrder] => false
)
)
)
)
[ResponseMetadata] => Array
(
[RequestId] => 42c3353b-d6af-459f-9421-5e8b7efb8ea8
)
)
Here each array is am order, Now i want to display one by one.. can anyone kindly help me how to i display.. Im using Yii2 Php framework for this project... Thank you..

It should be something like this:
$myArray['ListOrdersResult']['Orders']['Order'][0]['AmazonOrderId'] = '171-4557760-7388350';
function print_order($order) {
foreach ($order as $key1=>$val) {
if (is_array($val))
print_order($val);
else
print "$key1 = $val<br/>\r\n";
}
}
print_order($myArray['ListOrdersResult']['Orders']['Order']);

Related

Blocktrail payments API, How to get the values that adress receive

I'am tryng to get the value that an adress sent me on my adress, I have already setted up the webhook, but i can't understand a thing...
I have this array->
Array
(
[network] => tBTC
[event_type] => address-transactions
[addresses] => Array
(
[2MyXzRYSzrExLitY6FumGC3QgzCeqVoeQC1] => -49320
)
[data] => Array
(
[raw] =>
[hash] =>
[first_seen_at] => 2017-10-13T17:19:35+0000
[last_seen_at] => 2017-10-13T17:19:35+0000
[block_height] => 1210150
[block_time] => 2017-10-13T17:20:18+0000
[block_hash] =>
[confirmations] => 2
[is_coinbase] =>
[estimated_value] => 30000
[total_input_value] => 49320
[total_output_value] => 45510
[total_fee] => 3810
[estimated_change] => 15510
[estimated_change_address] => 2N7iSxafSoio4RE8wrd6outJNmbMkyP9QuL
[high_priority] =>
[enough_fee] =>
[contains_dust] =>
[inputs] => Array
(
[0] => Array
(
[index] => 0
[output_hash] =>
[output_index] => 0
[output_confirmed] => 1
[value] => 49320
[sequence] => 4294967295
[address] => 2MyXzRYSzrExLitY6FumGC3QgzCeqVoeQC1
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script_signature] =>
)
)
[outputs] => Array
(
[0] => Array
(
[index] => 0
[value] => 30000
[address] => 2NBkQ8aTq8yeXdMWtxXNuxNgEHYnrzvcpV2
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script] => OP_HASH160 OP_EQUAL
[script_hex] =>
[spent_hash] =>
[spent_index] => 0
)
[1] => Array
(
[index] => 1
[value] => 15510
[address] => 2N7iSxafSoio4RE8wrd6outJNmbMkyP9QuL
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script] => OP_HASH160 OP_EQUAL
[script_hex] =>
[spent_hash] =>
[spent_index] => 0
)
)
[opt_in_rbf] =>
[unconfirmed_inputs] =>
[lock_time_timestamp] =>
[lock_time_block_height] =>
[size] => 367
)
[retry_count] => 0
And I'am tryng to get ONLY THE VALUE OF BTC (SATOSHI) THAT COME ON MY ADRESS, SO WITH THE SUBSTRACTION OF THE FEES, i thought that for get this values I had to get the
$Data=BlocktrailSDK::getWebhookPayload();
$Data['data']['estimated_value'];
Is this correct way to get at the 1000000% THE VALUE OF BTC (SATOSHI) THAT COME ON MY ADRESS, SO WITH THE SUBSTRACTION OF THE FEES, if is not what is the correct way??Anyway thanks for ready, hope that you all had a good day, and thanks for your time :)
P.S Note that on this transaction i sent 30000 satoshi+fees!

I got this response from cleeng API ; how to convert this response to JSON

Cleeng_Entity_Collection Object
(
[entityType:protected] => Cleeng_Entity_SubscriptionOffer
[items:protected] => Array
(
[0] => Cleeng_Entity_SubscriptionOffer Object
(
[id:protected] => S955494970_US
[publisherEmail:protected] => vidya+mtc#ooyala.com
[url:protected] =>
[title:protected] => Annual subscription
[description:protected] =>
[period:protected] => year
[price:protected] => 49.99
[applicableTaxRate:protected] => 0
[currency:protected] => USD
[accessToTags:protected] => Array
(
[0] => d962607d3d4c4e3c98a343c7bcb64027
)
[active:protected] => 1
[createdAt:protected] => 1473681112
[updatedAt:protected] => 1473858745
[geoRestrictionEnabled:protected] =>
[geoRestrictionType:protected] =>
[geoRestrictionCountries:protected] => Array
(
)
[pending:protected] =>
[country] => US
[socialCommissionRate] => 0
[averageRating] => 4
[contentType] =>
[freePeriods] => 0
[freeDays] => 0
[expiresAt] =>
)
)
[totalItemCount:protected] => 5
[pending:protected] =>
)
All you need to do is just convert the Collection to a Regular Array and then json_encode() the Result like so:
<?php
$entityCollection = "???"; // THIS IS THE DATA FROM Cleeng_Entity_Collection Object
$entityArray = $entityCollection->toArray();
$entityJSON = json_encode($entityArray);

How to access values inside multidimensional array php

I have an array like this
Array
(
[TrackReply] => Array
(
[MoreData] => false
[TrackDetails] => Array
(
[Notification] => Array
(
[Severity] => SUCCESS
[Source] => trck
[Code] => 0
[Message] => Request was successfully processed.
[LocalizedMessage] => Request was successfully processed.
)
[TrackingNumber] => 123456789012
[TrackingNumberUniqueIdentifier] => 2457082000~123456789012~FX
[CarrierCode] => FDXE
[ServiceInfo] => FedEx International First
[ServiceType] => FIRST_OVERNIGHT
[PackageSequenceNumber] => 0
[PackageCount] => 0
[ShipTimestamp] => 2015-02-28T13:22:00+00:00
[DestinationAddress] => Array
(
[StateOrProvinceCode] => TN
[CountryCode] => US
[Residential] => false
)
)
)
)
Getting this array from $response and from this array how can i get "Notification->Message" value, please help me Thanks in advance
echo $array['TrackReply']['TrackDetails']['Notification']['Message'];
You have access using array
$arrayname['TrackReply']['TrackDetails']['Notification']['Message']

How to echo an array value

I am fairly new to PHP and I am writing a PHP function that grabs an object from SOAP.
I found a code to convert it to an array but I can't manage to echo any data.
The array from print_r
Array
(
[Status] => Array
(
[Code] => 0
[Message] => OK
)
[Order] => Array
(
[OrderNumber] => 9334543
[ExternalOrderNumber] =>
[OrderTime] => 2014-07-15T15:20:31+02:00
[PaymentMethod] => invoice
[PaymentStatus] => Paid
[ShipmentMethod] => Mypack
[DeliveryStatus] => Delivered
[Language] => sv
[Customer] => Array
(
[CustomerId] => 13556
[CustomerNumber] =>
[Username] => admin
[Approved] => 1
[OrgNumber] => 9309138445
[Company] =>
[VatNumber] =>
[FirstName] => Jane
[LastName] => Doe
[Address] => Gatan
[Address2] =>
[Zip] => 1230
[City] => Staden
[Country] => Sweden
[CountryCode] => SE
[PhoneDay] => 84848474
[PhoneNight] =>
[PhoneMobile] =>
[Email] => mail#msn.com
[NewsLetter] =>
[OrgType] => person
[OtherDelivAddress] =>
[DelivName] =>
[DelivAddress] =>
[DelivAddress2] =>
[DelivZip] =>
[DelivCity] =>
[DelivCountry] =>
[DelivCountryCode] =>
)
[Comment] =>
[Notes] => 9063025471 UK/MA
[CurrencyCode] => SEK
[ExchangeRate] => 1
[LanguagePath] => se
[FreightWithoutVat] => 0
[FreightWithVat] => 0
[FreightVatPercentage] => 25
[PayoptionFeeWithoutVat] => 0
[PayoptionFeeWithVat] => 0
[PayoptionFeeVatPercentage] => 25
[CodWithoutVat] => 0
[CodWithVat] => 0
[CodVatPercentage] => 0
[DiscountWithoutVat] => 0
[DiscountWithVat] => 0
[DiscountVat] => 0
[TotalWithoutVat] => 4388
[TotalWithVat] => 5485
[TotalVat] => 1097
[PayWithoutVat] =>
[AffiliateCode] =>
[AffiliateName] =>
[OrderField] => Array
(
[0] => Array
(
[Name] => external_ref
[Value] => 43445
)
[1] => Array
(
[Name] => webshopid
[Value] => 423
)
[2] => Array
(
[Name] => webshopname
[Value] => Manuell
)
)
)
)
Non working code
echo $array[1][0]
I have tried different combos of indexes. I know how to return the values from the soap object but if I could do it this way it would be easier. It should work shouldn't it?
$array[1] is the second index of the array. the key of this array us "Status", this array contains a code and message
i assume you want to echo the message, you can do that with the following
echo $array[1]["Status"]["Message"];
You should use $array['Status']['Code'] , $array['Status']['Message'], $array['Order']['OrderNumber'], $array['Order']['Customer']['CustomerId'] and so on to display your data. It's an associative array so you need to use string keys and not numbers
try
$array['Order']['Customer']['LastName']
is my best guess without losing my sanity in that one line.
But for us to be sure please post the print_r($array) output
There are some way I always do this:
print_r($array);
And the other way is
$array[0]['Order']['LastName']
Try to access the arrays elements with the string keys, not the integer ones you are using:
echo $array['Order']['Customer']['Address'];
Another way you could see what is going on is by iterating through the array, and print out the keys and values:
foreach ($array as $key => $value)
echo "Key=$key value=$value<br>";

Pass entire Array in php in another array

I have array with products its name is $item
Array
(
[0] => Array
(
[Quantity] => 2
[Product] => Array
(
[Name] => Barbula klandoa - Caryopteris clandonensis
[UnitPrice] => Array
(
[Gross] => 1480
[Net] => 0
[Tax] => 0
[TaxRate] => 0
[CurrencyCode] => PLN
)
)
)
[1] => Array
(
[Quantity] => 1
[Product] => Array
(
[Name] => Aronia czarnoowocowa Nero - Aronia melanocarpa Nero
[UnitPrice] => Array
(
[Gross] => 1200
[Net] => 0
[Tax] => 0
[TaxRate] => 0
[CurrencyCode] => PLN
)
)
)
[2] => Array
(
[Quantity] => 1
[Product] => Array
(
[Name] => Ambrowiec AmerykaƄski P9 - Liquidambar styraciflua
[UnitPrice] => Array
(
[Gross] => 1300
[Net] => 0
[Tax] => 0
[TaxRate] => 0
[CurrencyCode] => PLN
)
)
)
)
no i have to passed it to this:
$shoppingCart = array(
'GrandTotal' => ($suma_z_produktow*10),
'CurrencyCode' => 'PLN',
'ShoppingCartItems' => array (
array ('ShoppingCartItem' => $item)
)
);
Result is that only last entry from this array is passed to this new array.
I can nodifi it and pass it like that:
$shoppingCart = array(
'GrandTotal' => ($suma_z_produktow*10),
'CurrencyCode' => 'PLN',
'ShoppingCartItems' => array (
array ('ShoppingCartItem' => $item[0)
array ('ShoppingCartItem' => $item[1)
)
);
that method works, but I dont know how many product will customer order. Is there any method to pass all items in 1 row?
Its for Payu Payment method integration.
Thx
I think you need to tweak your code to get it to do what you want. Here is what I would recommend:
$shoppingCart = array(
'GrandTotal' => ($suma_z_produktow*10),
'CurrencyCode' => 'PLN',
'ShoppingCartItems' => array (),
);
foreach($item as $product) {
$shoppingCart['ShoppingCartItems'][] = array('ShoppingCartItem' => $product);
}
Try this:
$shoppingCart = array(
'GrandTotal' => ($suma_z_produktow*10),
'CurrencyCode' => 'PLN',
'ShoppingCartItems' => array (),
);
foreach($item as $cartItem){
$shoppingCart['ShoppingCartItems'][] = array('ShoppingCartItem'=>$cartItem);
}
print_r($shoppingCart);
This will build up the shoppingCartItems for as many items as you have.

Categories