Convert WSDL to array - php

I have a WSDL that is mapped to a variable
$client = new SoapClient($wsdl, array("connection_timeout"=>10));
It returns an array like:
stdClass Object
(
[getProductsReturn] => Array
(
[0] => stdClass Object
(
[barCode] => 5060285475448
[brandId] => 0
[childProductIds] => stdClass Object
(
)
[childProductIdsAsIntArray] => stdClass Object
(
)
[childProductIdsList] =>
[fullProductPaths] => Candles->Amber And Lavender Scented Sachet
[fullProductPathsArray] => stdClass Object
(
)
[id] => 5883
[image] =>
[imageId] => 0
[itemCount] => 1
[longDescription] =>
[masterProductId] => 5883
[message] =>
[messagePrice] => 0
[messageType] => 0
[optionId] => 0
[optionName] => null
[optionSetId] => 0
[optionSetName] => null
[orderType] => 5050
[parentProductCode] =>
[parentProductId] => 8088
[price] => 2.99
[productCode] => AA2485
[productId] => 0
[productType] => 1010
[quantity] => 0
[quantityPrice] => 0
[rrp] => 2.99
[shortDescription] => Amber And Lavender Scented Sachet
[variation] =>
[vatCodeDomainId] => 0
[wrappingPrice] => 0
[wrappingType] => 0
)
[1] => stdClass Object
(
[barCode] => 5060285475547
[brandId] => 0
[childProductIds] => stdClass Object
(
)
[childProductIdsAsIntArray] => stdClass Object
(
)
[childProductIdsList] =>
[fullProductPaths] => Candles->Lavender And Bergamot Scented Sachet
[fullProductPathsArray] => stdClass Object
(
)
[id] => 5881
[image] =>
[imageId] => 0
[itemCount] => 1
[longDescription] =>
[masterProductId] => 5881
[message] =>
[messagePrice] => 0
[messageType] => 0
[optionId] => 0
[optionName] => null
[optionSetId] => 0
[optionSetName] => null
[orderType] => 5050
[parentProductCode] =>
[parentProductId] => 8088
[price] => 2.99
[productCode] => AA2484
[productId] => 0
[productType] => 1010
[quantity] => 0
[quantityPrice] => 0
[rrp] => 2.99
[shortDescription] => Lavender And Bergamot Scented Sachet
[variation] =>
[vatCodeDomainId] => 0
[wrappingPrice] => 0
[wrappingType] => 0
)
I want to show this in a HTML and this is what I had given in the for loop:
<pre>
foreach ($product as $products) {
$currentStockQuantity = $product->barCode($products);
echo $currentStockQuantity;
echo $products->barCode;
echo $products[$i]->shortDescription;
echo $products[$i]->barCode;
$i++;
}
But it is not showing all the products, there are about 100 products but only one is showing at the moment

Assuming you stored the result array from your WSDL in a $products variable, you could try:
foreach ($products as $product) {
echo $product->shortDescription;
echo $product->barCode;
// ... and whatever you want
}
More information about foreach: http://php.net/manual/en/control-structures.foreach.php

Related

Accessing second array (non object) in decoded JSON

I'm trying to access the second array (contacts) in this decoded json to grab the ID next to first_name (the two ID keys could be different), but the second array doesn't seem to be an object so I can't find a loop which can acces it:
stdClass Object (
[data] => Array (
[0] => stdClass Object (
[account_key] => jvg7qgtw2btrlmpigrq2zpco48eegxvv
[is_owner] => 1
[id] => 1
[name] => test test
[display_name] => test test
[balance] => 0
[paid_to_date] => 0
[updated_at] => 1578494555
[archived_at] =>
[address1] => Street
[address2] =>
[city] => Town
[state] => State
[postal_code] => Code
[country_id] => 0
[work_phone] => Number
[private_notes] =>
[public_notes] =>
[last_login] =>
[website] =>
[industry_id] => 0
[size_id] => 0
[is_deleted] =>
[payment_terms] => 30
[vat_number] =>
[id_number] =>
[language_id] => 0
[currency_id] => 0
[custom_value1] =>
[custom_value2] =>
[invoice_number_counter] => 1
[quote_number_counter] => 1
[task_rate] => 0
[shipping_address1] =>
[shipping_address2] =>
[shipping_city] =>
[shipping_state] =>
[shipping_postal_code] =>
[shipping_country_id] => 0
[show_tasks_in_portal] => 1
[send_reminders] => 1
[credit_number_counter] => 1
[custom_messages] => {}
[contacts] => Array (
[0] => stdClass Object (
[account_key] => jvg7qgtw2btrlmpigrq2zpco48eegxvv
[is_owner] => 1
[id] => 1
[first_name] => test
[last_name] => test
[email] => myemail#me.com
[contact_key] => mq1dzpkqznfgtqwhdwt9nte1ohmvsju1
[updated_at] => 1578494555
[archived_at] =>
[is_primary] => 1
[phone] => 07919446174
[last_login] =>
[send_invoice] => 1
[custom_value1] =>
[custom_value2] =>
)
)
)
)
[meta] => stdClass Object (
[pagination] => stdClass Object (
[total] => 1
[count] => 1
[per_page] => 15
[current_page] => 1
[total_pages] => 1
[links] => Array ( )
)
)
)
This is what I've tried, but it doesn't find anything:
$person = getclient($itemid);
$person_data = json_decode($person);
foreach ($person_data->contacts as $key => $item)
{
$itemid = $item->id . "<br />";
}
$person_data contains the data property, which is an array of objects.
foreach ($person_data->data as $person) {
foreach ($person->contacts as $contact) {
echo $contact->id . '<br>';
}
}

How to print complicated multidimensional array through foreach loop in php

I have an Multi Dimensional array like below.
<?php$array = Array ( [ResultIndex] => OB4 [Source] => 3 [IsLCC] => 1 [IsRefundable] => [GSTAllowed] => [AirlineRemark] => this is a test from aditya [Fare] => Array ( [Currency] => INR [BaseFare] => 865 [Tax] => 613 [TaxBreakup] => Array ( [0] => Array ( [key] => YQTax [value] => 0 ) [1] => Array ( [key] => YR [value] => 0 ) [2] => Array ( [key] => PSF [value] => 0 ) [3] => Array ( [key] => UDF [value] => 0 ) [4] => Array ( [key] => JNTax [value] => 52 ) [5] => Array ( [key] => INTax [value] => 0 ) [6] => Array ( [key] => TransactionFee [value] => 0 ) [7] => Array ( [key] => OtherTaxes [value] => 0 ) ) [YQTax] => 0 [AdditionalTxnFeeOfrd] => 0 [AdditionalTxnFeePub] => 0 [PGCharge] => 0 [OtherCharges] => 0 [ChargeBU] => Array ( [0] => Array ( [key] => TBOMARKUP [value] => 0 ) [1] => Array ( [key] => CONVENIENCECHARGE [value] => 0 ) [2] => Array ( [key] => OTHERCHARGE [value] => 0 ) ) [Discount] => 0 [PublishedFare] => 1478 [CommissionEarned] => 22.06 [PLBEarned] => 14.09 [IncentiveEarned] => 14.33 [OfferedFare] => 1427.52 [TdsOnCommission] => 4.41 [TdsOnPLB] => 2.82 [TdsOnIncentive] => 2.87 [ServiceFee] => 0 [TotalBaggageCharges] => 0 [TotalMealCharges] => 0 [TotalSeatCharges] => 0 [TotalSpecialServiceCharges] => 0 ) [FareBreakdown] => Array ( [0] => Array ( [Currency] => INR [PassengerType] => 1 [PassengerCount] => 1 [BaseFare] => 865 [Tax] => 613 [YQTax] => 0 [AdditionalTxnFeeOfrd] => 0 [AdditionalTxnFeePub] => 0 [PGCharge] => 0 ) ) [Segments] => Array ( [0] => Array ( [0] => Array ( [Baggage] => 10 Kg [CabinBaggage] => 7 Kg [TripIndicator] => 1 [SegmentIndicator] => 1 [Airline] => Array ( [AirlineCode] => SG [AirlineName] => SpiceJet [FlightNumber] => 1033 [FareClass] => C [OperatingCarrier] => ) [NoOfSeatAvailable] => 4 [Origin] => Array ( [Airport] => Array ( [AirportCode] => BLR [AirportName] => Hindustan [Terminal] => [CityCode] => BLR [CityName] => Bangalore [CountryCode] => IN [CountryName] => India ) [DepTime] => 2017-10-21T17:40:00 ) [Destination] => Array ( [Airport] => Array ( [AirportCode] => MAA [AirportName] => Chennai [Terminal] => [CityCode] => MAA [CityName] => Chennai [CountryCode] => IN [CountryName] => India ) [ArrTime] => 2017-10-21T18:40:00 ) [Duration] => 60 [GroundTime] => 0 [Mile] => 0 [StopOver] => [StopPoint] => [StopPointArrivalTime] => 2017-10-21T18:40:00 [StopPointDepartureTime] => 2017-10-21T17:40:00 [Craft] => DH8 [Remark] => [IsETicketEligible] => 1 [FlightStatus] => Confirmed [Status] => ) ) ) [LastTicketDate] => [TicketAdvisory] => [FareRules] => Array ( [0] => Array ( [Origin] => BLR [Destination] => MAA [Airline] => SG [FareBasisCode] => CSAVER [FareRuleDetail] => [FareRestriction] => ) ) [AirlineCode] => SG [ValidatingAirline] => SG );?>
how to make it print using foreach loop in php. if any one have idea to rectify this please suggest me

Trying to get property of non-object in C:\wamp... (Accesing Object Array Value )

$result is
stdClass Object
(
[cityId] => 000000000020
[checkInDate] => 2013-12-20
[checkOutDate] => 2013-12-21
[customerId] =>
[customerAccountType] => SH01
[customerType] =>
[currency] => INR
[noOfRoomsRequested] => 1
[searchAvailabilityResult] => stdClass Object
(
[hotelId] => IXW1
[hotelName] => Ginger Jamshedpur
[Rate] => stdClass Object
(
[rateId] => STANDARD
[rateVersion] =>
[contractId] =>
[contractVersion] => 000
[allocationId] => IBE
[perPaxRateTypeSet] =>
[taxInclusiveInRateFlag] =>
[price] => 3499
[offerPrice] => 3499
[packageCost] => 0
[taxAmount] => 0
[luxuryTax] => 437.38
[serviceTax] => 216.24
[offerPercentageDiscount] => 0
[offerIdentifier] =>
[displayType] =>
[rateIdentifierType] => STANDARD
[rateIdTypeDesc] => STANDARD RATE
[conceptIdentifier] => ONLYROOM
[packageIdentifier] =>
[smartRate] =>
[roomGrid] => stdClass Object
(
[room] => Array
(
[0] => stdClass Object
(
[roomNumber] => 1
[roomType] => TWN
[pricingType] =>
[numOfPax] => 1
[numberOfAdults] => 1
[numberOfChildren] => 0
[numberOfJuniors] => 0
[numOfPaxForWhichRateApplied] => 1
[numOfpaxStaying] => 0
[conceptId] => ONLYROOM
[isAlternative] =>
[packageCost] => 0
[taxAmount] => 0
[luxuryTax] => 437.38
[serviceTax] => 216.24
[dayWiseRate] => stdClass Object
(
[forDay] => stdClass Object
(
[date] => 2013-12-20
[price] => 3499
[offerPrice] => 3499
[taxAmount] => 0
[luxuryTax] => 437.38
[serviceTax] => 216.24
[availability] => 42
)
)
)
[1] => stdClass Object
(
[roomNumber] => 1
[roomType] => STD
[pricingType] =>
[numOfPax] => 1
[numberOfAdults] => 1
[numberOfChildren] => 0
[numberOfJuniors] => 0
[numOfPaxForWhichRateApplied] => 1
[numOfpaxStaying] => 0
[conceptId] => ONLYROOM
[isAlternative] => 1
[packageCost] => 0
[taxAmount] => 0
[luxuryTax] => 437.38
[serviceTax] => 216.24
[dayWiseRate] => stdClass Object
(
[forDay] => stdClass Object
(
[date] => 2013-12-20
[price] => 3499
[offerPrice] => 3499
[taxAmount] => 0
[luxuryTax] => 437.38
[serviceTax] => 216.24
[availability] => 21
)
)
)
)
)
[policies] => stdClass Object
(
[policy] => Array
(
[0] => stdClass Object
(
[policyType] => ADV
[policyCode] => ADVIXW1001
)
[1] => stdClass Object
(
[policyType] => CAN
[policyCode] => CNXIXW1002
)
[2] => stdClass Object
(
[policyType] => AMD
[policyCode] => AMDIXW1002
)
[3] => stdClass Object
(
[policyType] => NOS
[policyCode] => NSIXW1002
)
[4] => stdClass Object
(
[policyType] => CCP
[policyCode] => CIOIXW1001
)
)
)
)
)
)
i want to access [rateIdTypeDesc] => STANDARD RATE
what i tried
foreach ($result->searchAvailabilityResult->Rate as $item)
{
echo $item->rateIdTypeDesc; echo "<hr>";
}
Notice: Trying to get property of non-object in C:\wamp
foreach ($result->searchAvailabilityResult->Rate as $key=>$item) {
if($key == 'rateIdTypeDesc'){
echo $item;
}
}

Filter large PHP array

This data is return from Flickr API. It contains 1000 arrays with photo details. The array is given below...
Array
(
[0] => Array
(
[id] => 8437769421
[owner] => 10817753#N03
[secret] => 9eccf2d244
[server] => 8056
[farm] => 9
[title] => [Group 1]-XR6A1835_XR6A1840-6 images-E.jpg
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[description] => Array
(
[_content] => Stitched Panorama
)
[dateupload] => 1359826577
[datetaken] => 2012-12-24 10:32:04
[datetakengranularity] => 0
[ownername] => Ulf Bodin
[tags] => mist fog landscape spain ray rays andalusia andalusien spanien landskap salobreña dimma canoneos5dmarkiii canonef70200mmf28lisiiusm
[latitude] => 36.743055
[longitude] => -3.588651
[accuracy] => 16
[context] => 0
[place_id] => qvlfaYpWVbiHFTA
[woeid] => 772523
[geo_is_family] => 0
[geo_is_friend] => 0
[geo_is_contact] => 0
[geo_is_public] => 1
)
[1] => Array
(
[id] => 8437770275
[owner] => 69309429#N02
[secret] => 1805477eb0
[server] => 8078
[farm] => 9
[title] => #Newfoundlanddogs #squirellhatersclub #landseer #newfie #dogs #newfiesofinstagram #instadogs #drool #newfiesarethebestdogsever
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[description] => Array
(
[_content] =>
)
[dateupload] => 1359826595
[datetaken] => 2013-02-02 09:36:35
[datetakengranularity] => 0
[ownername] => chefwaiterhater
[tags] => square squareformat normal iphoneography instagramapp uploaded:by=instagram
[latitude] => 0
[longitude] => 0
[accuracy] => 0
[context] => 0
)
.....
.....
.....
[999] => Array
(
[id] => 8438855962
[owner] => 23123736#N00
[secret] => ab5b4dbf4d
[server] => 8092
[farm] => 9
[title] => Dusky drama - drive home
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[description] => Array
(
[_content] =>
)
[dateupload] => 1359826602
[datetaken] => 2013-02-02 17:36:42
[datetakengranularity] => 0
[ownername] => angee09
[tags] => square squareformat iphoneography instagramapp xproii uploaded:by=instagram
[latitude] => 0
[longitude] => 0
[accuracy] => 0
[context] => 0
)
);
I want to filter array only containing latitude for that I write this program...
function onlyLatLng($items)
{
$filters = array();
foreach ($items as $item) {
if (!in_array($item['latitude'], array('0', '', 'NULL'))) {
$filters[] = $item;
}
}
return $filters;
}
$latlngs = onlyLatLng($above_big_array);
Is this right way to do? or there is better way to filter the array? Thanks in advance.
You could use the array_filter function:
$latlngs = array_filter($items, function ($item) {
return !in_array($item['latitude'], array('0', '', 'NULL')));
});

PHP Acess multi array object of WP Shopping Cart items

I have array which gets from session, this is print_r of array
print_r($_SESSION['wpsc_cart']);
wpsc_cart Object ( [delivery_country] => AU [selected_country] => AU [delivery_region] => [selected_region] => [selected_shipping_method] => [selected_shipping_option] => [selected_shipping_amount] => [coupon] => [tax_percentage] => 0 [unique_id] => 98b4abe821cda949c0a6feedcd51487134765124 [errors] => Array ( ) [total_tax] => [base_shipping] => [total_item_shipping] => [total_shipping] => [subtotal] => 105 [total_price] => [uses_shipping] => [is_incomplete] => 1 [cart_items] => Array ( [0] => wpsc_cart_item Object ( [cart] => wpsc_cart Object *RECURSION* [product_id] => 1675 [variation_values] => [product_variations] => [variation_data] => [quantity] => 1 [provided_price] => [product_name] => Gift Card [category_list] => Array ( [0] => 30 ) [category_id_list] => Array ( [0] => 13 ) [unit_price] => 30 [total_price] => 30 [taxable_price] => 0 [tax] => 0 [weight] => 0 [shipping] => 0 [sku] => [product_url] => http://www.activefeet.com.au/products-page/30/gift-card [image_id] => [thumbnail_image] => [custom_tax_rate] => [meta] => Array ( [0] => Array ( [wpec_taxes_taxable_amount] => [external_link] => [external_link_text] => [external_link_target] => [weight] => 0 [weight_unit] => pound [dimensions] => Array ( [height] => 0 [height_unit] => in [width] => 0 [width_unit] => in [length] => 0 [length_unit] => in ) [shipping] => Array ( [local] => 5 [international] => 5 ) [no_shipping] => 1 [merchant_notes] => [engraved] => 0 [can_have_uploaded_image] => 0 [enable_comments] => [unpublish_when_none_left] => 0 [quantity_limited] => 0 [special] => 0 [display_weight_as] => pound [table_rate_price] => Array ( [quantity] => Array ( ) [table_price] => Array ( ) ) [google_prohibited] => 0 ) ) [is_donation] => 0 [apply_tax] => 1 [priceandstock_id] => 0 [custom_message] => [custom_file] => [comment] => [time_requested] => [file_data] => [is_customisable] => [stock] => [uses_shipping] => 0 [has_limited_stock] => [file_id] => [is_downloadable] => ) [1] => wpsc_cart_item Object ( [cart] => wpsc_cart Object *RECURSION* [product_id] => 1679 [variation_values] => [product_variations] => [variation_data] => [quantity] => 1 [provided_price] => [product_name] => Gift Card [category_list] => Array ( [0] => 76 ) [category_id_list] => Array ( [0] => 15 ) [unit_price] => 75 [total_price] => 75 [taxable_price] => 0 [tax] => 0 [weight] => 0 [shipping] => 0 [sku] => [product_url] => http://www.activefeet.com.au/products-page/76/gift-card-3 [image_id] => [thumbnail_image] => [custom_tax_rate] => [meta] => Array ( [0] => Array ( [wpec_taxes_taxable_amount] => [external_link] => [external_link_text] => [external_link_target] => [weight] => 0 [weight_unit] => pound [dimensions] => Array ( [height] => 0 [height_unit] => in [width] => 0 [width_unit] => in [length] => 0 [length_unit] => in ) [shipping] => Array ( [local] => 0 [international] => 0 ) [merchant_notes] => [engraved] => 0 [can_have_uploaded_image] => 0 [enable_comments] => [unpublish_when_none_left] => 0 [no_shipping] => 0 [quantity_limited] => 0 [special] => 0 [display_weight_as] => pound [table_rate_price] => Array ( [quantity] => Array ( ) [table_price] => Array ( ) ) [google_prohibited] => 0 ) ) [is_donation] => 0 [apply_tax] => 1 [priceandstock_id] => 0 [custom_message] => [custom_file] => [comment] => [time_requested] => [file_data] => [is_customisable] => [stock] => [uses_shipping] => 1 [has_limited_stock] => [file_id] => [is_downloadable] => ) ) [cart_item] => wpsc_cart_item Object ( [cart] => wpsc_cart Object *RECURSION* [product_id] => 1675 [variation_values] => [product_variations] => [variation_data] => [quantity] => 1 [provided_price] => [product_name] => Gift Card [category_list] => Array ( [0] => 30 ) [category_id_list] => Array ( [0] => 13 ) [unit_price] => 30 [total_price] => 30 [taxable_price] => 0 [tax] => 0 [weight] => 0 [shipping] => 0 [sku] => [product_url] => http://www.activefeet.com.au/products-page/30/gift-card [image_id] => [thumbnail_image] => [custom_tax_rate] => [meta] => Array ( [0] => Array ( [wpec_taxes_taxable_amount] => [external_link] => [external_link_text] => [external_link_target] => [weight] => 0 [weight_unit] => pound [dimensions] => Array ( [height] => 0 [height_unit] => in [width] => 0 [width_unit] => in [length] => 0 [length_unit] => in ) [shipping] => Array ( [local] => 5 [international] => 5 ) [no_shipping] => 1 [merchant_notes] => [engraved] => 0 [can_have_uploaded_image] => 0 [enable_comments] => [unpublish_when_none_left] => 0 [quantity_limited] => 0 [special] => 0 [display_weight_as] => pound [table_rate_price] => Array ( [quantity] => Array ( ) [table_price] => Array ( ) ) [google_prohibited] => 0 ) ) [is_donation] => 0 [apply_tax] => 1 [priceandstock_id] => 0 [custom_message] => [custom_file] => [comment] => [time_requested] => [file_data] => [is_customisable] => [stock] => [uses_shipping] => 0 [has_limited_stock] => [file_id] => [is_downloadable] => ) [cart_item_count] => 2 [current_cart_item] => -1 [in_the_loop] => [shipping_methods] => [shipping_method] => [shipping_method_count] => 1 [current_shipping_method] => -1 [in_the_method_loop] => [shipping_quotes] => [shipping_quote] => [shipping_quote_count] => 0 [current_shipping_quote] => -1 [in_the_quote_loop] => [coupons_name] => [coupons_amount] => 0 [shipping_option] => )
I need to get items from this array
[no_shipping] => 1
[no_shipping] => 0
using some foreach or.. i have no idea about this, please help me..
thank you
i directly use the object, it is easy than convert session to object
foreach($wpsc_cart->cart_items as $i => $Item) {
$cv=$Item->meta;
foreach($cv as $vc=>$it){
echo $it['no_shipping'];
}
}

Categories