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']
Related
I have the following array:
Array (
[result] => Array (
[id] => 58fba3ebf4
[type] => A
[name] => ser.domain.com
[content] => 192.168.100.1
[proxiable] =>
[proxied] =>
[ttl] => 1
[priority] => 10
[locked] =>
[zone_id] => eb0d86828e3ac837c
[zone_name] => domain.com
[modified_on] => 2018-07-06T06:37:14.069598Z
[created_on] => 2018-07-06T06:37:14.069598Z
[meta] => Array (
[auto_added] =>
[managed_by_apps] =>
[managed_by_argo_tunnel] =>
)
)
[success] => 1
[errors] => Array ( )
[messages] => Array ( )
)
How can I just get the value from id?
$data =json_decode($response);
$id = $data->result->id;
Assuming your payload from the request was $response.
You already have a multi-dimensional array so just try like this
echo $arrays['result']['id']; // this will return id
echo $arrays['result']['type']; // this will return type
Here is solution
// $result_array() is your reponse from curl PHP
$data = $result_array();
$id = $data['result']['id'];
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']);
i am trying to calculate shipping charge and i am getting a response from REST API. i want to get return the value of "delivery_charges" form response array?
Array
(
[response] => Array
(
[delivery_charges] => 41
[return_charges] => 83
[all_charges] => Array
(
[DL] => 32
[FS] => 30
[DTO] => 0
[RTO] => 32
[ST] => 14.5
[COD] => 0
[TDS] => 0
[CARD] => 0
[CNC] => 0
)
[canc_charges] => 0
[pickup_charges] => 0
[params] => Array
(
[md] => E
[pt] => prepaid
[cl] => xxxxxxx
[o_pin] => 560076
[d_pin] => 560062
[token] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[gm] => 100
[d_city] => Bangalore
[o_city] => Bangalore
)
)
)
i got answer by just using
return $shipping_charge['response']['delivery_charges'];
You need to simply add the following at the end. If $shipping_charge is the array then write:
return $shipping_charge['response']['delivery_charges'];
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>";
I am experimenting with my first API and getting stuck with the results. I am getting an Array Back:
Array
(
[GetOrderListResult] => Array
(
[Status] => Success
[MessageCode] => 0
[ResultData] => Array
(
[OrderResponseItem] => Array
(
[0] => Array
(
[NumberOfMatches] => 2
[OrderTimeGMT] => 2014-05-05T03:23:00
[LastUpdateDate] => 2014-05-28T11:41:45.953
[TotalOrderAmount] => 12.7800
[OrderState] => Active
[DateCancelledGMT] =>
[OrderID] => 138711
[ClientOrderIdentifier] => 138711
[SellerOrderID] =>
[OrderStatus] => Array
(
[CheckoutStatus] => NotVisited
[CheckoutDateGMT] => 1900-01-01T00:00:00
[PaymentStatus] => NotSubmitted
[PaymentDateGMT] => 1900-01-01T00:00:00
[ShippingStatus] => Unshipped
[ShippingDateGMT] => 1900-01-01T00:00:00
[OrderRefundStatus] => NoRefunds
)
)
[1] => Array
(
[NumberOfMatches] => 2
[OrderTimeGMT] => 2014-05-05T03:23:00
[LastUpdateDate] => 2014-05-28T12:59:01.78
[TotalOrderAmount] => 6.3900
[OrderState] => Active
[DateCancelledGMT] =>
[OrderID] => 138750
[ClientOrderIdentifier] => 138750
[SellerOrderID] =>
[OrderStatus] => Array
(
[CheckoutStatus] => NotVisited
[CheckoutDateGMT] => 1900-01-01T00:00:00
[PaymentStatus] => NotSubmitted
[PaymentDateGMT] => 1900-01-01T00:00:00
[ShippingStatus] => Unshipped
[ShippingDateGMT] => 1900-01-01T00:00:00
[OrderRefundStatus] => NoRefunds
)
)
)
)
)
)
Now the onyl way I know how to reference a fied such as the order id in the array is:
echo "Order ID: ".$result['GetOrderListResult']['ResultData']['OrderResponseItem']['0']['OrderID'];
But I want to be able to loop through the array of orders and execute code for each item, could somewbody please point me in the right direction for:
a) is there a better way to refernce these fields?
b) how do I loop through the OrderResponseItem part of the array?
The only loop I could think of was for the whole array not nested items in the array.
Sorry if I'm missing something simple....
Thanks and if you need the data in any other format please let me know.
Since you already know the keys you could just use a foreach to access them an point to that key then loop. Something like this:
foreach($result['GetOrderListResult']['ResultData']['OrderResponseItem'] as $value) {
$order_id = $value['OrderID'];
// your other processes
}