Paypal API Refund Payment (PHP API) - php

this is my first time posting:
I wish to integrate PayPal API into my site, I can get the payment successfully done but not the refund part. I see an refund api in the lib folder; however, I am not sure which ID to use, I don't see a lot of examples regarding refund.
This is what I have now:
$refund = new Refund();
$refund->setId($payment_id);
$refund->setAmount(1000);
$refund->get($payment_id, $this->apiContext);
try {
//$refund = Refund::get();
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
return json_decode($payment, 128);
Where Payment Detail is:
array(10) {
["id"]=>
string(28) "PAY-1WL153218P032830GKZK2BLY"
["intent"]=>
string(4) "sale"
["state"]=>
string(7) "created"
["cart"]=>
string(17) "08X596883D298843B"
["payer"]=>
array(3) {
["payment_method"]=>
string(6) "paypal"
["status"]=>
string(8) "VERIFIED"
["payer_info"]=>
array(8) {
["email"]=>
string(32) "ted.chou12-facilitator#gmail.com"
["first_name"]=>
string(4) "test"
["last_name"]=>
string(11) "facilitator"
["payer_id"]=>
string(13) "GGYZW23EGRAY4"
["shipping_address"]=>
array(7) {
["recipient_name"]=>
string(16) "test facilitator"
["line1"]=>
string(22) "88 Des Voeux Road West"
["line2"]=>
string(6) "3F 520"
["city"]=>
string(9) "Hong Kong"
["state"]=>
string(9) "Hong Kong"
["postal_code"]=>
string(6) "000000"
["country_code"]=>
string(2) "HK"
}
["phone"]=>
string(10) "4088069385"
["country_code"]=>
string(2) "US"
["billing_address"]=>
array(6) {
["line1"]=>
string(22) "88 Des Voeux Road West"
["line2"]=>
string(6) "3F 520"
["city"]=>
string(9) "Hong Kong"
["state"]=>
string(9) "Hong Kong"
["postal_code"]=>
string(6) "000000"
["country_code"]=>
string(2) "HK"
}
}
}
["transactions"]=>
array(1) {
[0]=>
array(6) {
["amount"]=>
array(3) {
["total"]=>
string(7) "2340.00"
["currency"]=>
string(3) "TWD"
["details"]=>
array(3) {
["subtotal"]=>
string(7) "2310.00"
["tax"]=>
string(4) "0.00"
["shipping"]=>
string(5) "30.00"
}
}
["payee"]=>
array(1) {
["email"]=>
string(35) "jaypatel512-facilitator#hotmail.com"
}
["description"]=>
string(19) "Payment description"
["invoice_number"]=>
string(13) "5655a0adceedf"
["item_list"]=>
array(2) {
["items"]=>
array(3) {
[0]=>
array(5) {
["name"]=>
string(2) "25"
["sku"]=>
string(2) "11"
["price"]=>
string(6) "529.00"
["currency"]=>
string(3) "TWD"
["quantity"]=>
int(3)
}
[1]=>
array(5) {
["name"]=>
string(13) "Warrior Model"
["sku"]=>
string(2) "15"
["price"]=>
string(6) "180.00"
["currency"]=>
string(3) "TWD"
["quantity"]=>
int(1)
}
[2]=>
array(5) {
["name"]=>
string(7) "dim_sum"
["sku"]=>
string(2) "22"
["price"]=>
string(6) "543.00"
["currency"]=>
string(3) "TWD"
["quantity"]=>
int(1)
}
}
["shipping_address"]=>
array(7) {
["recipient_name"]=>
string(16) "test facilitator"
["line1"]=>
string(22) "88 Des Voeux Road West"
["line2"]=>
string(6) "3F 520"
["city"]=>
string(9) "Hong Kong"
["state"]=>
string(9) "Hong Kong"
["postal_code"]=>
string(6) "000000"
["country_code"]=>
string(2) "HK"
}
}
["related_resources"]=>
array(0) {
}
}
}
["redirect_urls"]=>
array(2) {
["return_url"]=>
string(97) "..."
["cancel_url"]=>
string(59) "..."
}
["create_time"]=>
string(20) "2015-11-25T11:51:10Z"
["update_time"]=>
string(20) "2015-11-25T11:51:10Z"
["links"]=>
array(3) {
[0]=>
array(3) {
["href"]=>
string(79) "..."
["rel"]=>
string(4) "self"
["method"]=>
string(3) "GET"
}
[1]=>
array(3) {
["href"]=>
string(87) ".../execute"
["rel"]=>
string(7) "execute"
["method"]=>
string(4) "POST"
}
[2]=>
array(3) {
["href"]=>
string(94) "..."
["rel"]=>
string(12) "approval_url"
["method"]=>
string(8) "REDIRECT"
}
}
}

Once you execute the payment, you will get back a sale=>id. That's the id you would use for a refund.
It will also include a full URI for you under transactions=>related_resources=>links with the 'rel' value of 'refund'.
Source: https://developer.paypal.com/docs/api/#refunds

Each of the payment will produce an sale_id as an example 4CFG677234DFG234F. This ID will be use to make a refund.
Don't get yourself confuse with the payment id and the sale_id.

Related

PHP: Convert Google Sheets result object to simple array

I've google sheet with this data:
I'm pulling it from google drive with simple code:
$ranges = [
'Price_1'
];
$params = array(
'ranges' => $ranges
);
$response = $service->spreadsheets_values->batchGet($spreadsheetId, $params);
The response is a complicated object:
object(Google_Service_Sheets_BatchGetValuesResponse)#58 (8) { ["collection_key":protected]=> string(11) "valueRanges" ["spreadsheetId"]=> string(44) "1BQpKLuvlaVeGqIqoGUOynF9IZ5C3zK6gagZiRJO1UEU" ["valueRangesType":protected]=> string(32) "Google_Service_Sheets_ValueRange" ["valueRangesDataType":protected]=> string(5) "array" ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } ["valueRanges"]=> array(1) { [0]=> object(Google_Service_Sheets_ValueRange)#67 (7) { ["collection_key":protected]=> string(6) "values" ["majorDimension"]=> string(4) "ROWS" ["range"]=> string(14) "Price_1!E2:E74" ["values"]=> array(65) { [0]=> array(1) { [0]=> string(2) "28" } [1]=> array(1) { [0]=> string(2) "14" } [2]=> array(1) { [0]=> string(1) "0" } [3]=> array(0) { } [4]=> array(1) { [0]=> string(2) "55" } [5]=> array(1) { [0]=> string(2) "28" } [6]=> array(1) { [0]=> string(1) "0" } [7]=> array(0) { } [8]=> array(0) { } [9]=> array(0) { } [10]=> array(0) { } [11]=> array(0) { } [12]=> array(0) { } [13]=> array(0) { } [14]=> array(0) { } [15]=> array(0) { } [16]=> array(0) { } [17]=> array(0) { } [18]=> array(0) { } [19]=> array(0) { } [20]=> array(1) { [0]=> string(2) "59" } [21]=> array(1) { [0]=> string(2) "49" } [22]=> array(0) { } [23]=> array(1) { [0]=> string(2) "38" } [24]=> array(1) { [0]=> string(2) "38" } [25]=> array(0) { } [26]=> array(1) { [0]=> string(2) "37" } [27]=> array(1) { [0]=> string(2) "25" } [28]=> array(1) { [0]=> string(1) "0" } [29]=> array(0) { } [30]=> array(1) { [0]=> string(2) "79" } [31]=> array(1) { [0]=> string(2) "99" } [32]=> array(0) { } [33]=> array(1) { [0]=> string(2) "75" } [34]=> array(1) { [0]=> string(2) "99" } [35]=> array(0) { } [36]=> array(1) { [0]=> string(2) "79" } [37]=> array(1) { [0]=> string(2) "99" } [38]=> array(0) { } [39]=> array(1) { [0]=> string(3) "160" } [40]=> array(1) { [0]=> string(3) "190" } [41]=> array(0) { } [42]=> array(0) { } [43]=> array(0) { } [44]=> array(0) { } [45]=> array(0) { } [46]=> array(0) { } [47]=> array(0) { } [48]=> array(0) { } [49]=> array(0) { } [50]=> array(0) { } [51]=> array(0) { } [52]=> array(1) { [0]=> string(2) "33" } [53]=> array(0) { } [54]=> array(1) { [0]=> string(2) "59" } [55]=> array(1) { [0]=> string(2) "34" } [56]=> array(1) { [0]=> string(1) "0" } [57]=> array(0) { } [58]=> array(1) { [0]=> string(2) "29" } [59]=> array(1) { [0]=> string(2) "14" } [60]=> array(1) { [0]=> string(1) "0" } [61]=> array(0) { } [62]=> array(1) { [0]=> string(2) "37" } [63]=> array(1) { [0]=> string(2) "25" } [64]=> array(1) { [0]=> string(1) "0" } } ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } } } }
and var_dump($response->getValueRanges()[0]['values']); gives this result:
array(74) { [0]=> array(5) { [0]=> string(2) "ID" [1]=> string(10) "Ticket for" [2]=> string(9) "Excursion" [3]=> string(8) "Duration" [4]=> string(14) "Price (Brutto)" } [1]=> array(5) { [0]=> string(3) "01A" [1]=> string(13) "adult ( 12+ )" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(2) "28" } [2]=> array(5) { [0]=> string(3) "01B" [1]=> string(18) "child ( age 5-11 )" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(2) "14" } [3]=> array(5) { [0]=> string(3) "01C" [1]=> string(18) "toodler ( age 0-4)" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(1) "0" } [4]=> array(0) { } [5]=> array(5) { [0]=> string(3) "02A" [1]=> string(13) "adult, age 8+" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(2) "55" } [6]=> array(5) { [0]=> string(3) "02B" [1]=> string(14) "child, age 3-7" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(2) "28" } [7]=> array(5) { [0]=> string(3) "02C" [1]=> string(16) "toodler, age 0-2" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(1) "0" } [8]=> array(0) { } [9]=> array(3) { [0]=> string(3) "03A" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [10]=> array(3) { [0]=> string(3) "03B" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [11]=> array(3) { [0]=> string(3) "03C" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [12]=> array(0) { } [13]=> array(3) { [0]=> string(3) "04A" [1]=> string(0) "" [2]=> string(9) "Submarine" } [14]=> array(3) { [0]=> string(3) "04B" [1]=> string(0) "" [2]=> string(9) "Submarine" } [15]=> array(3) { [0]=> string(3) "04C" [1]=> string(0) "" [2]=> string(9) "Submarine" } [16]=> array(0) { } [17]=> array(3) { [0]=> string(3) "05A" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [18]=> array(3) { [0]=> string(3) "05B" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [19]=> array(3) { [0]=> string(3) "05C" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [20]=> array(0) { } [21]=> array(5) { [0]=> string(3) "06A" [1]=> string(9) "fisherman" [2]=> string(7) "Fishing" [3]=> string(2) "4h" [4]=> string(2) "59" } [22]=> array(5) { [0]=> string(3) "06B" [1]=> string(9) "spectator" [2]=> string(7) "Fishing" [3]=> string(2) "4h" [4]=> string(2) "49" } [23]=> array(0) { } [24]=> array(5) { [0]=> string(3) "07A" [1]=> string(5) "adult" [2]=> string(12) "Parascending" [3]=> string(5) "30min" [4]=> string(2) "38" } [25]=> array(5) { [0]=> string(3) "07B" [1]=> string(13) "child, age 6+" [2]=> string(12) "Parascending" [3]=> string(5) "30min" [4]=> string(2) "38" } [26]=> array(0) { } [27]=> array(5) { [0]=> string(3) "08A" [1]=> string(14) "adult, age 12+" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(2) "37" } [28]=> array(5) { [0]=> string(3) "08B" [1]=> string(15) "child, age 3-11" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(2) "25" } [29]=> array(5) { [0]=> string(3) "08C" [1]=> string(16) "toodler, age 0-1" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(1) "0" } [30]=> array(0) { } [31]=> array(5) { [0]=> string(3) "09A" [1]=> string(17) "flight from 800m." [2]=> string(18) "Paragliding tandem" [3]=> string(5) "15min" [4]=> string(2) "79" } [32]=> array(5) { [0]=> string(3) "09B" [1]=> string(18) "flight from 1000m." [2]=> string(18) "Paragliding tandem" [3]=> string(5) "25min" [4]=> string(2) "99" } [33]=> array(0) { } [34]=> array(5) { [0]=> string(3) "10A" [1]=> string(21) "Single (for 1 person)" [2]=> string(27) "Quad safari Forest explorer" [3]=> string(2) "3h" [4]=> string(2) "75" } [35]=> array(5) { [0]=> string(3) "10B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(27) "Quad safari Forest explorer" [3]=> string(2) "3h" [4]=> string(2) "99" } [36]=> array(0) { } [37]=> array(5) { [0]=> string(3) "11A" [1]=> string(21) "Single (for 1 person)" [2]=> string(24) "Quad Safari - Teide tour" [3]=> string(2) "4h" [4]=> string(2) "79" } [38]=> array(5) { [0]=> string(3) "11B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(24) "Quad Safari - Teide tour" [3]=> string(2) "4h" [4]=> string(2) "99" } [39]=> array(0) { } [40]=> array(5) { [0]=> string(3) "12A" [1]=> string(21) "Single (for 1 person)" [2]=> string(15) "Buggy adventure" [3]=> string(2) "3h" [4]=> string(3) "160" } [41]=> array(5) { [0]=> string(3) "12B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(15) "Buggy adventure" [3]=> string(2) "3h" [4]=> string(3) "190" } [42]=> array(0) { } [43]=> array(3) { [0]=> string(3) "13A" [1]=> string(0) "" [2]=> string(8) "Trekking" } [44]=> array(3) { [0]=> string(3) "13B" [1]=> string(0) "" [2]=> string(8) "Trekking" } [45]=> array(3) { [0]=> string(3) "13C" [1]=> string(0) "" [2]=> string(8) "Trekking" } [46]=> array(0) { } [47]=> array(3) { [0]=> string(3) "14A" [1]=> string(0) "" [2]=> string(7) "Karting" } [48]=> array(3) { [0]=> string(3) "14B" [1]=> string(0) "" [2]=> string(7) "Karting" } [49]=> array(3) { [0]=> string(3) "14C" [1]=> string(0) "" [2]=> string(7) "Karting" } [50]=> array(0) { } [51]=> array(3) { [0]=> string(3) "15A" [1]=> string(0) "" [2]=> string(11) "Jungle park" } [52]=> array(3) { [0]=> string(3) "15B" [1]=> string(0) "" [2]=> string(11) "Jungle park" } [53]=> array(5) { [0]=> string(3) "15C" [1]=> string(0) "" [2]=> string(11) "Jungle park" [3]=> string(0) "" [4]=> string(2) "33" } [54]=> array(0) { } [55]=> array(5) { [0]=> string(3) "16A" [1]=> string(14) "adult, age 12+" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(2) "59" } [56]=> array(5) { [0]=> string(3) "16B" [1]=> string(15) "child, age 2-11" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(2) "34" } [57]=> array(5) { [0]=> string(3) "16C" [1]=> string(16) "toodler, age 0-1" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(1) "0" } [58]=> array(0) { } [59]=> array(5) { [0]=> string(3) "17A" [1]=> string(14) "adult, age 12+" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(2) "29" } [60]=> array(5) { [0]=> string(3) "17B" [1]=> string(15) "child, age 2-11" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(2) "14" } [61]=> array(5) { [0]=> string(3) "17C" [1]=> string(16) "toodler, age 0-1" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(1) "0" } [62]=> array(0) { } [63]=> array(5) { [0]=> string(3) "18A" [1]=> string(14) "adult, age 12+" [2]=> string(11) "Loro parque" [3]=> string(12) "8:30 - 18:45" [4]=> string(2) "37" } [64]=> array(5) { [0]=> string(3) "18B" [1]=> string(15) "child, age 6-11" [2]=> string(11) "Loro parque" [3]=> string(0) "" [4]=> string(2) "25" } [65]=> array(5) { [0]=> string(3) "18C" [1]=> string(16) "toodler, age 0-1" [2]=> string(11) "Loro parque" [3]=> string(0) "" [4]=> string(1) "0" } [66]=> array(0) { } [67]=> array(3) { [0]=> string(3) "19A" [1]=> string(0) "" [2]=> string(9) "Antologia" } [68]=> array(3) { [0]=> string(3) "19B" [1]=> string(0) "" [2]=> string(9) "Antologia" } [69]=> array(3) { [0]=> string(3) "19C" [1]=> string(0) "" [2]=> string(9) "Antologia" } [70]=> array(0) { } [71]=> array(3) { [0]=> string(3) "20A" [1]=> string(0) "" [2]=> string(13) "Medieval show" } [72]=> array(3) { [0]=> string(3) "20B" [1]=> string(0) "" [2]=> string(13) "Medieval show" } [73]=> array(3) { [0]=> string(3) "20C" [1]=> string(0) "" [2]=> string(13) "Medieval show" } }
And:
for($i = 1; $i < 5; $i++) {
print_r ($response->getValueRanges()[0]['values'][$i]);
}
Gives: Array ( [0] => 01A [1] => adult ( 12+ ) [2] => Catamaran [3] => 2h [4] => 28 ) Array ( [0] => 01B [1] => child ( age 5-11 ) [2] => Catamaran [3] => 2h [4] => 14 ) Array ( [0] => 01C [1] => toodler ( age 0-4) [2] => Catamaran [3] => 2h [4] => 0 ) Array ( )
In result I need a simple array, which will hold a key[row id], the ID from from ID row and price from last row, somethig like this: $result[$i] = unique_id=1, ID=01A, price=28
How it could be achieved?
So after getting the data for google sheet with:
$arr = $response->getValueRanges()[0]['values'];
You can use this simple for loop to get the data as you need:
// notice start from 1 to avoid the headers
for($i = 1; $i < count($arr); $i++) {
$res[$i] = array("unique_id" => $i, "ID" => $arr[$i][0], "price" => $arr[$i][4]);
}
Now $res will contain you structure.

SimpleXml array to string PHP

My PHP function is returning a SimpleXML array like this:
array(1) { [0]=> object(SimpleXMLElement)#6 (18) { ["#attributes"]=> array(6) { ["thumbnailUrl"]=> string(47) "users/908/721/swagg_ma_blue/thumbnail-12612.jpg" ["default"]=> string(1) "1" ["name"]=> string(5) "_copy" ["color"]=> string(8) "0xBB9977" ["mood"]=> string(1) "3" ["species"]=> string(4) "stud" } ["head"]=> object(SimpleXMLElement)#5 (1) { ["#attributes"]=> array(4) { ["url"]=> string(51) "http://assets.zwinky.com/assets/stud/heads/01/head1" ["c"]=> string(8) "0xF2B38A" ["c2"]=> string(8) "0xffffff" ["z"]=> string(5) "33000" } } ["face"]=> object(SimpleXMLElement)#7 (1) { ["#attributes"]=> array(5) { ["url"]=> string(51) "http://assets.zwinky.com/assets/stud/faces/01/stud1" ["c"]=> string(8) "0xFFFFFF" ["displayName"]=> string(5) "stud1" ["z"]=> string(5) "34000" ["id"]=> string(8) "20017217" } } ["belt"]=> array(2) { [0]=> object(SimpleXMLElement)#8 (1) { ["#attributes"]=> array(6) { ["url"]=> string(64) "http://assets.zwinky.com/assets/store/zwinky/stud/belts/01/Vblt1" ["c"]=> string(8) "0x000000" ["c2"]=> string(8) "0xFFFFFF" ["displayName"]=> string(30) "Tough Love Belt ketamine-dolly" ["z"]=> string(5) "20100" ["id"]=> string(8) "20098984" } } [1]=> object(SimpleXMLElement)#20 (1) { ["#attributes"]=> array(5) { ["url"]=> string(76) "http://ak.ugc.zwinky.com/zwinky/fds/creations/791/402/z-justin/1441479408229" ["isUgc"]=> string(4) "true" ["displayName"]=> string(9) "My Design" ["z"]=> string(5) "20100" ["id"]=> string(8) "20081015" } } } ["midsection"]=> object(SimpleXMLElement)#9 (1) { ["#attributes"]=> array(2) { ["url"]=> string(55) "http://assets.zwinky.com/assets/stud/midsections/01/ms1" ["z"]=> string(4) "9000" } } ["leg"]=> object(SimpleXMLElement)#10 (1) { ["#attributes"]=> array(2) { ["url"]=> string(50) "http://assets.zwinky.com/assets/stud/legs/01/legs1" ["z"]=> string(5) "10000" } } ["hair"]=> object(SimpleXMLElement)#11 (1) { ["#attributes"]=> array(6) { ["url"]=> string(62) "http://assets.zwinky.com/assets/store/zwinky/stud/hair/01/Zhr8" ["c"]=> string(8) "0xD0C0B0" ["c2"]=> string(8) "0x000000" ["displayName"]=> string(7) "spiky 3" ["z"]=> string(5) "37000" ["id"]=> string(8) "20013196" } } ["shirt"]=> object(SimpleXMLElement)#12 (1) { ["#attributes"]=> array(5) { ["url"]=> string(63) "http://assets.zwinky.com/assets/store/zwinky/stud/tops/01/Vtop2" ["c"]=> string(8) "0x212121" ["displayName"]=> string(8) "tank top" ["z"]=> string(5) "21000" ["id"]=> string(8) "20012196" } } ["jacket"]=> object(SimpleXMLElement)#13 (1) { ["#attributes"]=> array(5) { ["url"]=> string(76) "http://ak.ugc.zwinky.com/zwinky/fds/creations/113/681/b4d_b0yy/1452451820582" ["isUgc"]=> string(4) "true" ["displayName"]=> string(4) "asdf" ["z"]=> string(5) "30000" ["id"]=> string(8) "20080934" } } ["bottom"]=> object(SimpleXMLElement)#14 (1) { ["#attributes"]=> array(6) { ["url"]=> string(67) "http://assets.zwinky.com/assets/store/zwinky/stud/bottoms/01/MXbm14" ["c"]=> string(8) "0xD6D6D6" ["c2"]=> string(8) "0xFFFFFF" ["displayName"]=> string(15) "Steampunk Pants" ["z"]=> string(5) "20000" ["id"]=> string(8) "20039549" } } ["electronic"]=> object(SimpleXMLElement)#15 (1) { ["#attributes"]=> array(5) { ["url"]=> string(64) "http://assets.zwinky.com/assets/store/zwinky/stud/misc/01/SDmis1" ["c"]=> string(8) "0x3366FF" ["displayName"]=> string(12) "game player2" ["z"]=> string(5) "45000" ["id"]=> string(8) "20017518" } } ["hat"]=> object(SimpleXMLElement)#16 (1) { ["#attributes"]=> array(5) { ["url"]=> string(49) "http://assets.zwinky.com/assets/stud/hats/01/hat6" ["c"]=> string(3) "0x0" ["displayName"]=> string(13) "baseball cap2" ["z"]=> string(5) "40000" ["id"]=> string(8) "20017403" } } ["earrings"]=> object(SimpleXMLElement)#17 (1) { ["#attributes"]=> array(4) { ["url"]=> string(52) "http://assets.zwinky.com/assets/stud/earrings/01/er2" ["displayName"]=> string(10) "gold hoops" ["z"]=> string(5) "39000" ["id"]=> string(8) "20017442" } } ["bracelet"]=> object(SimpleXMLElement)#18 (1) { ["#attributes"]=> array(6) { ["url"]=> string(67) "http://assets.zwinky.com/assets/store/zwinky/stud/bracelets/01/Zbr1" ["c"]=> string(8) "0xFFFFFF" ["c2"]=> string(8) "0xB5B5B5" ["displayName"]=> string(13) "Leather Cuffs" ["z"]=> string(5) "13000" ["id"]=> string(8) "20013217" } } ["necklace"]=> object(SimpleXMLElement)#19 (1) { ["#attributes"]=> array(5) { ["url"]=> string(68) "http://assets.zwinky.com/assets/store/zwinky/stud/necklaces/01/SDnk1" ["c"]=> string(8) "0xffffff" ["displayName"]=> string(14) "Snoop Necklace" ["z"]=> string(5) "23000" ["id"]=> string(8) "20012554" } } ["facialhair"]=> object(SimpleXMLElement)#21 (1) { ["#attributes"]=> array(5) { ["url"]=> string(69) "http://assets.zwinky.com/assets/store/zwinky/stud/facialhair/01/Vfhr1" ["c"]=> string(8) "0xffffff" ["displayName"]=> string(16) "Evil Cupid beard" ["z"]=> string(5) "38000" ["id"]=> string(8) "20012194" } } ["food"]=> object(SimpleXMLElement)#22 (1) { ["#attributes"]=> array(4) { ["url"]=> string(64) "http://assets.zwinky.com/assets/store/zwinky/stud/misc/01/HWmis7" ["displayName"]=> string(11) "mug w/steam" ["z"]=> string(5) "47000" ["id"]=> string(8) "20017604" } } ["facialdecorations"]=> object(SimpleXMLElement)#23 (1) { ["#attributes"]=> array(5) { ["url"]=> string(88) "http://ak.ugc.zwinky.com/zwinky/fds/creations/235/447/simsea-gdh0thtb1tzch/1426865152881" ["isUgc"]=> string(4) "true" ["displayName"]=> string(9) "My Design" ["z"]=> string(5) "42500" ["id"]=> string(8) "20081020" } } } }
My function looks like the following:
function get_user_outfit(){
$zwinky_login = $this->curl_post_login();
if($zwinky_login){
$user_outfit = $this->curl_post('http://outfits.zwinky.com/users/' . $this->user_directories() . '/outfits.xml', false, $this->cookie, true, false);
$xml = simplexml_load_string($user_outfit);
$element = $xml->xpath("//outfit[#default=1]");
return $element;
}else{
return 'Could not login.';
}
}
and I can't find a way to translate this into a string.
I've been trying the following http://php.net/manual/en/simplexmlelement.asxml.php which wouldnt work.
Does anyone have a idea?
$xml->xpath(...) returns an array of nodes of the type SimpleXMLElement.
There's built in functions to convert it to a string, although you'll have to loop through the returned nodes.
E.g.
$nodes = $xml->path(...);
$str = '';
foreach($nodes as $node){
$str .= $node->asXML();
}
return $str;
If you want the value of a node, you can invoke the magic method __toString on the SimpleXMLElement object. E.g. echo $node['attribute']; or echo $xml->path('//outfit[#default=1]/some/name')[0];
Alternatively use PHP DOM which gives you a lot more control and flexibility.

Echo array with json_decode gives too many echoes

I do get the strings I intend to. But I also get the first letter (or number) of the other data in the json file.
E.g. I would like to have or should get the result:
/Barrafina
Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here.
Matt Ta-Min/
But instead I get
/Barrafina
ee
Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here.
5 5 E Eu uh h
Matt Ta-Min
/
What did I do wrong? here is the code:
(If you have time and energy to look the JSON you will see from where eg. 5 5 E Eu uh h comes.)
I appreciate any help.
<?php
$client_id = 'CLIENT_ID';
$client_secret = 'SECRET';
$request_date = date('Ymd');
$base_url = 'https://api.foursquare.com/v2/';
$endpoint = 'venues/explore?';
$params = 'near=London&limit=3&section=food&radius=1000';
$auth = "&client_id=$client_id&client_secret=$client_secret&v=$request_date";
$url = $base_url.$endpoint.$params.$auth;
$results = file_get_contents($url);
$json_results = json_decode($results,true);
//var_dump($json_results);
$items0 = $json_results['response']['groups']['0']['items']['0'];
$items1 = $json_results['response']['groups']['0']['items']['0']['tips'];
$items2 = $json_results['response']['groups']['0']['items']['0']['tips']['0'];
//<div style="align:center;">
foreach ( $items0+$items1 as $item){
echo '<li>';
echo $item['name'];
echo $item['text'];
}
foreach ( $items2 as $item){
print $item['firstName']; print '&nbsp'; print $item['lastName'];
}
HERE is the json decoded:
array(2) { ["meta"]=> array(2) { ["code"]=> int(200) ["requestId"]=> string(24) "55fb1f91498e70ad2e246eed" } ["response"]=> array(10) { ["suggestedFilters"]=> array(2) { ["header"]=> string(12) "Tap to show:" ["filters"]=> array(2) { [0]=> array(2) { ["name"]=> string(13) "With specials" ["key"]=> string(8) "specials" } [1]=> array(2) { ["name"]=> string(8) "Open now" ["key"]=> string(7) "openNow" } } } ["geocode"]=> array(8) { ["what"]=> string(0) "" ["where"]=> string(6) "london" ["center"]=> array(2) { ["lat"]=> float(51.50853) ["lng"]=> float(-0.12574) } ["displayString"]=> string(38) "London, Greater London, United Kingdom" ["cc"]=> string(2) "GB" ["geometry"]=> array(1) { ["bounds"]=> array(2) { ["ne"]=> array(2) { ["lat"]=> float(51.691643999656) ["lng"]=> float(0.33418999705203) } ["sw"]=> array(2) { ["lat"]=> float(51.284674044171) ["lng"]=> float(-0.50855792793694) } } } ["slug"]=> string(6) "london" ["longId"]=> string(17) "72057594040571679" } ["warning"]=> array(1) { ["text"]=> string(114) "There aren't a lot of results near you. Try something more general, reset your filters, or expand the search area." } ["headerLocation"]=> string(6) "London" ["headerFullLocation"]=> string(6) "London" ["headerLocationGranularity"]=> string(4) "city" ["query"]=> string(4) "food" ["totalResults"]=> int(246) ["suggestedBounds"]=> array(2) { ["ne"]=> array(2) { ["lat"]=> float(51.510800358799) ["lng"]=> float(-0.12174369837641) } ["sw"]=> array(2) { ["lat"]=> float(51.508100699014) ["lng"]=> float(-0.13015278468604) } } ["groups"]=> array(1) { [0]=> array(3) { ["type"]=> string(18) "Recommended Places" ["name"]=> string(11) "recommended" ["items"]=> array(1) { [0]=> array(4) { ["reasons"]=> array(2) { ["count"]=> int(0) ["items"]=> array(1) { [0]=> array(3) { ["summary"]=> string(20) "This spot is popular" ["type"]=> string(7) "general" ["reasonName"]=> string(23) "globalInteractionReason" } } } ["venue"]=> array(17) { ["id"]=> string(24) "53bab96d498e7e355fb53d6c" ["name"]=> string(9) "Barrafina" ["contact"]=> array(6) { ["phone"]=> string(13) "+442074401456" ["formattedPhone"]=> string(16) "+44 20 7440 1456" ["twitter"]=> string(13) "barrafinaadst" ["facebook"]=> string(15) "705351912878392" ["facebookUsername"]=> string(23) "BarrafinaAdelaideStreet" ["facebookName"]=> string(25) "Barrafina Adelaide Street" } ["location"]=> array(10) { ["address"]=> string(14) "10 Adelaide St" ["crossStreet"]=> string(13) "William IV St" ["lat"]=> float(51.509450528906) ["lng"]=> float(-0.12594824153122) ["postalCode"]=> string(8) "WC2N 4HZ" ["cc"]=> string(2) "GB" ["city"]=> string(6) "London" ["state"]=> string(14) "Greater London" ["country"]=> string(14) "United Kingdom" ["formattedAddress"]=> array(5) { [0]=> string(30) "10 Adelaide St (William IV St)" [1]=> string(6) "London" [2]=> string(14) "Greater London" [3]=> string(8) "WC2N 4HZ" [4]=> string(14) "United Kingdom" } } ["categories"]=> array(1) { [0]=> array(6) { ["id"]=> string(24) "4bf58dd8d48988d150941735" ["name"]=> string(18) "Spanish Restaurant" ["pluralName"]=> string(19) "Spanish Restaurants" ["shortName"]=> string(7) "Spanish" ["icon"]=> array(2) { ["prefix"]=> string(52) "https://ss3.4sqi.net/img/categories_v2/food/spanish_" ["suffix"]=> string(4) ".png" } ["primary"]=> bool(true) } } ["verified"]=> bool(false) ["stats"]=> array(3) { ["checkinsCount"]=> int(357) ["usersCount"]=> int(278) ["tipCount"]=> int(26) } ["url"]=> string(22) "http://barrafina.co.uk" ["price"]=> array(3) { ["tier"]=> int(2) ["message"]=> string(8) "Moderate" ["currency"]=> string(2) "£" } ["rating"]=> float(9) ["ratingColor"]=> string(6) "00B551" ["ratingSignals"]=> int(80) ["allowMenuUrlEdit"]=> bool(true) ["hours"]=> array(2) { ["status"]=> string(19) "Open until 11:00 PM" ["isOpen"]=> bool(true) } ["specials"]=> array(2) { ["count"]=> int(0) ["items"]=> array(0) { } } ["photos"]=> array(2) { ["count"]=> int(31) ["groups"]=> array(0) { } } ["hereNow"]=> array(3) { ["count"]=> int(0) ["summary"]=> string(11) "Nobody here" ["groups"]=> array(0) { } } } ["tips"]=> array(1) { [0]=> array(9) { ["id"]=> string(24) "55db9142498ede18f5b31b81" ["createdAt"]=> int(1440452930) ["text"]=> string(164) "Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here." ["type"]=> string(4) "user" ["canonicalUrl"]=> string(52) "https://foursquare.com/item/55db9142498ede18f5b31b81" ["likes"]=> array(3) { ["count"]=> int(2) ["groups"]=> array(0) { } ["summary"]=> string(7) "2 likes" } ["logView"]=> bool(true) ["todo"]=> array(1) { ["count"]=> int(0) } ["user"]=> array(5) { ["id"]=> string(8) "98683884" ["firstName"]=> string(4) "Matt" ["lastName"]=> string(6) "Ta-Min" ["gender"]=> string(4) "male" ["photo"]=> array(2) { ["prefix"]=> string(31) "https://irs1.4sqi.net/img/user/" ["suffix"]=> string(30) "/98683884-1MJ0OTISTPZWSBRJ.jpg" } } } } ["referralId"]=> string(30) "e-3-53bab96d498e7e355fb53d6c-0" } } } } } }
Here is JSON
{"meta":{"code":200,"requestId":"55fbde58498e7fdbd12f8fb2"},"response":{"suggestedFilters":{"header":"Tap to show:","filters":[{"name":"With specials","key":"specials"},{"name":"Open now","key":"openNow"}]},"geocode":{"what":"","where":"london","center":{"lat":51.50853,"lng":-0.12574},"displayString":"London, Greater London, United Kingdom","cc":"GB","geometry":{"bounds":{"ne":{"lat":51.691643999655895,"lng":0.33418999705203406},"sw":{"lat":51.28467404417054,"lng":-0.5085579279369435}}},"slug":"london","longId":"72057594040571679"},"warning":{"text":"There aren't a lot of results near you. Try something more general, reset your filters, or expand the search area."},"headerLocation":"London","headerFullLocation":"London","headerLocationGranularity":"city","query":"food","totalResults":246,"suggestedBounds":{"ne":{"lat":51.5108003587992,"lng":-0.12174369837640672},"sw":{"lat":51.50810069901375,"lng":-0.1301527846860385}},"groups":[{"type":"Recommended Places","name":"recommended","items":[{"reasons":{"count":0,"items":[{"summary":"This spot is popular","type":"general","reasonName":"globalInteractionReason"}]},"venue":{"id":"53bab96d498e7e355fb53d6c","name":"Barrafina","contact":{"phone":"+442074401456","formattedPhone":"+44 20 7440 1456","twitter":"barrafinaadst","facebook":"705351912878392","facebookUsername":"BarrafinaAdelaideStreet","facebookName":"Barrafina Adelaide Street"},"location":{"address":"10 Adelaide St","crossStreet":"William IV St","lat":51.50945052890648,"lng":-0.1259482415312226,"postalCode":"WC2N 4HZ","cc":"GB","city":"London","state":"Greater London","country":"United Kingdom","formattedAddress":["10 Adelaide St (William IV St)","London","Greater London","WC2N 4HZ","United Kingdom"]},"categories":[{"id":"4bf58dd8d48988d150941735","name":"Spanish Restaurant","pluralName":"Spanish Restaurants","shortName":"Spanish","icon":{"prefix":"https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/spanish_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":357,"usersCount":278,"tipCount":26},"url":"http:\/\/barrafina.co.uk","rating":9.0,"ratingColor":"00B551","ratingSignals":80,"allowMenuUrlEdit":true,"hours":{"status":"Closed until Noon","isOpen":false},"specials":{"count":0,"items":[]},"photos":{"count":31,"groups":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]}},"tips":[{"id":"55db9142498ede18f5b31b81","createdAt":1440452930,"text":"Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here.","type":"user","canonicalUrl":"https:\/\/foursquare.com\/item\/55db9142498ede18f5b31b81","likes":{"count":2,"groups":[],"summary":"2 likes"},"logView":true,"todo":{"count":0},"user":{"id":"98683884","firstName":"Matt","lastName":"Ta-Min","gender":"male","photo":{"prefix":"https:\/\/irs1.4sqi.net\/img\/user\/","suffix":"\/98683884-1MJ0OTISTPZWSBRJ.jpg"}}}],"referralId":"e-3-53bab96d498e7e355fb53d6c-0"}]}]}}

How to get object like value:item:private from PHP Array

I have the array like this:
} ["items":"Jcart":private]=> array(3) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
[2]=>
string(7) "ABC-123" }
How to get the "items" values in a php variable?
///////
Te complete object is:
object(Jcart)#1 (8) {
["config"]=>
array(12) {
["jcartPath"]=>
string(6) "jcart/"
["checkoutPath"]=>
string(12) "checkout.php"
["item"]=>
array(6) {
["id"]=>
string(10) "my-item-id"
["name"]=>
string(12) "my-item-name"
["price"]=>
string(13) "my-item-price"
["qty"]=>
string(11) "my-item-qty"
["url"]=>
string(11) "my-item-url"
["add"]=>
string(13) "my-add-button"
}
["paypal"]=>
array(5) {
["id"]=>
string(38) "seller_1282188508_biz#conceptlogic.com"
["https"]=>
bool(true)
["sandbox"]=>
bool(false)
["returnUrl"]=>
string(0) ""
["notifyUrl"]=>
string(0) ""
}
["currencyCode"]=>
string(3) "USD"
["csrfToken"]=>
bool(false)
["text"]=>
array(14) {
["cartTitle"]=>
string(13) "Shopping Cart"
["singleItem"]=>
string(4) "Item"
["multipleItems"]=>
string(5) "Items"
["subtotal"]=>
string(8) "Subtotal"
["update"]=>
string(6) "update"
["checkout"]=>
string(8) "checkout"
["checkoutPaypal"]=>
string(20) "Checkout with PayPal"
["removeLink"]=>
string(6) "remove"
["emptyButton"]=>
string(5) "empty"
["emptyMessage"]=>
string(19) "Your cart is empty!"
["itemAdded"]=>
string(11) "Item added!"
["priceError"]=>
string(21) "Invalid price format!"
["quantityError"]=>
string(38) "Item quantities must be whole numbers!"
["checkoutError"]=>
string(34) "Your order could not be processed!"
}
["button"]=>
array(4) {
["checkout"]=>
string(0) ""
["paypal"]=>
string(0) ""
["update"]=>
string(0) ""
["empty"]=>
string(0) ""
}
["tooltip"]=>
bool(true)
["decimalQtys"]=>
bool(false)
["decimalPlaces"]=>
int(1)
["priceFormat"]=>
array(3) {
["decimals"]=>
int(2)
["dec_point"]=>
string(1) "."
["thousands_sep"]=>
string(1) ","
}
}
["items":"Jcart":private]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
}
["names":"Jcart":private]=>
array(2) {
[3]=>
string(12) "Hockey Stick"
[2]=>
string(13) "Baseball Mitt"
}
["prices":"Jcart":private]=>
array(2) {
[3]=>
string(5) "33.25"
[2]=>
string(5) "19.50"
}
["qtys":"Jcart":private]=>
array(2) {
[3]=>
string(1) "1"
[2]=>
string(2) "20"
}
["urls":"Jcart":private]=>
array(2) {
[3]=>
string(15) "http://bing.com"
[2]=>
string(16) "http://yahoo.com"
}
["subtotal":"Jcart":private]=>
float(423.25)
["itemCount":"Jcart":private]=>
int(21)
}
I just need the values in ["items":"Jcart":private]
I assume you got this by casting an object to an array. If that's the case, you shouldn't be doing that! The property is private because you're not supposed to access it directly because it's not a public API. The object should have a public method which you're supposed to call instead, that's the public API. Something like $foo->getItems() or such. Read the documentation and/or source code.

Loaded an XML file response, how do I get the data out of it now?

I received this XML data and var_dumped it.
How do I use this now and fetch one of the records from inside? like $this->{product}->name etc.?
object(SimpleXMLElement)#189 (1) { ["products"]=> object(SimpleXMLElement)#188 (2) { ["#attributes"]=> array(3) { ["total-matched"]=> string(1) "3" ["records-returned"]=> string(1) "3" ["page-number"]=> string(1) "1" } ["product"]=> array(3) { [0]=> object(SimpleXMLElement)#206 (19) { ["ad-id"]=> string(8) "10581256" ["advertiser-id"]=> string(7) "2466656" ["advertiser-name"]=> string(18) "Everydaysource.com" ["advertiser-category"]=> string(21) "MP3 Accessories>Cases" ["buy-url"]=> string(245) "http://www.kqzyfj.com/click-4107027-10581256?url=http%3A%2F%2Fwww.everydaysource.com%2Fproduct%2Fsnap-on-case-compatible-with-apple-ipod-touch-4th-gen-colorful-zebra%2Fdapptoucco62%3Fesaffcojudtf120626%3Daf%2Bcj%2Bdapptoucco62&cjsku=DAPPTOUCCO62" ["catalog-id"]=> string(8) "cjo:2691" ["currency"]=> string(3) "USD" ["description"]=> string(57) "Compatible With Apple®:iPod touch® 4th Generation" ["image-url"]=> string(73) "http://cdn1.everydaysource.com/cdn2/110207/fb/28/d2/dapptoucco62_1_es.jpg" ["in-stock"]=> object(SimpleXMLElement)#98 (0) { } ["isbn"]=> object(SimpleXMLElement)#99 (0) { } ["manufacturer-name"]=> string(14) "EverydaySource" ["manufacturer-sku"]=> string(12) "DAPPTOUCCO62" ["name"]=> string(69) "Snap-on Case Compatible with Apple iPod Touch 4th Gen,Colorful Zebra" ["price"]=> string(4) "8.99" ["retail-price"]=> string(3) "0.0" ["sale-price"]=> string(3) "0.0" ["sku"]=> string(12) "DAPPTOUCCO62" ["upc"]=> string(12) "628569324674" } [1]=> object(SimpleXMLElement)#100 (19) { ["ad-id"]=> string(8) "10402409" ["advertiser-id"]=> string(7) "1636472" ["advertiser-name"]=> string(8) "Eforcity" ["advertiser-category"]=> string(21) "MP3 Accessories>Cases" ["buy-url"]=> string(233) "http://www.jdoqocy.com/click-4107027-10402409?url=http%3A%2F%2Fwww.eforcity.com%2Fsnap-on-case-compatible-with-apple-ipod-touch-4th-gen-colorful-zebra-dapptoucco62.html%3Fefaffcojudtf120626%3Daf%2Bcj%2Bdapptoucco62&cjsku=DAPPTOUCCO62" ["catalog-id"]=> string(8) "cjo:1136" ["currency"]=> string(3) "USD" ["description"]=> string(57) "Compatible With Apple®:iPod touch® 4th Generation" ["image-url"]=> string(68) "http://cdn1.eforcity.com/cdn2/110101/41/86/a3/dapptoucco62_1_efc.jpg" ["in-stock"]=> object(SimpleXMLElement)#99 (0) { } ["isbn"]=> object(SimpleXMLElement)#98 (0) { } ["manufacturer-name"]=> string(8) "eForCity" ["manufacturer-sku"]=> string(12) "DAPPTOUCCO62" ["name"]=> string(69) "Snap-on Case Compatible with Apple iPod Touch 4th Gen,Colorful Zebra" ["price"]=> string(4) "7.99" ["retail-price"]=> string(3) "0.0" ["sale-price"]=> string(3) "0.0" ["sku"]=> string(12) "DAPPTOUCCO62" ["upc"]=> string(12) "628569324674" } [2]=> object(SimpleXMLElement)#101 (19) { ["ad-id"]=> string(8) "10581247" ["advertiser-id"]=> string(7) "2466659" ["advertiser-name"]=> string(15) "iTrimming Corp." ["advertiser-category"]=> string(21) "MP3 Accessories>Cases" ["buy-url"]=> string(165) "http://www.dpbolvw.net/click-4107027-10581247?url=http%3A%2F%2Fwww.itrimming.com%2Fdapptoucco62.html%3Fitaffcojudtf120626%3Daf%2Bcj%2Bdapptoucco62&cjsku=DAPPTOUCCO62" ["catalog-id"]=> string(8) "cjo:2690" ["currency"]=> string(3) "USD" ["description"]=> string(57) "Compatible With Apple®:iPod touch® 4th Generation" ["image-url"]=> string(68) "http://cdn1.itrimming.com/cdn2/110301/c9/cc/33/dapptoucco62_1_it.jpg" ["in-stock"]=> object(SimpleXMLElement)#98 (0) { } ["isbn"]=> object(SimpleXMLElement)#99 (0) { } ["manufacturer-name"]=> string(9) "iTrimming" ["manufacturer-sku"]=> string(12) "DAPPTOUCCO62" ["name"]=> string(69) "Snap-on Case Compatible with Apple iPod Touch 4th Gen,Colorful Zebra" ["price"]=> string(4) "7.59" ["retail-price"]=> string(3) "0.0" ["sale-price"]=> string(3) "0.0" ["sku"]=> string(12) "DAPPTOUCCO62" ["upc"]=> string(12) "628569324674" } } } }
Pastebin of the same : http://pastebin.com/XYN8ysEG
Thank you!
** Edit **
Here is the raw data
object(SimpleXMLElement)#189 (1) {
["products"]=>
object(SimpleXMLElement)#188 (2) {
["#attributes"]=>
array(3) {
["total-matched"]=>
string(1) "4"
["records-returned"]=>
string(1) "4"
["page-number"]=>
string(1) "1"
}
["product"]=>
array(4) {
[0]=>
object(SimpleXMLElement)#206 (19) {
["ad-id"]=>
string(8) "10450940"
["advertiser-id"]=>
string(7) "1427863"
["advertiser-name"]=>
string(12) "Bookbyte.com"
["advertiser-category"]=>
string(5) "Books"
["buy-url"]=>
string(151) "http://www.anrdoezrs.net/click-4107027-10450940?url=http%3A%2F%2Fwww.bookbyte.com%2Fproduct.aspx%3Fisbn%3D1576751740%26noredirect%3Dtrue&cjsku=13671976"
["catalog-id"]=>
string(8) "cjo:1574"
["currency"]=>
string(3) "USD"
["description"]=>
string(34) "This book is in Like New condition"
["image-url"]=>
object(SimpleXMLElement)#77 (0) {
}
["in-stock"]=>
object(SimpleXMLElement)#74 (0) {
}
["isbn"]=>
string(10) "1576751740"
["manufacturer-name"]=>
object(SimpleXMLElement)#75 (0) {
}
["manufacturer-sku"]=>
object(SimpleXMLElement)#72 (0) {
}
["name"]=>
string(53) "Leadership and Self Deception: Getting Out of the Box"
["price"]=>
string(4) "13.5"
["retail-price"]=>
string(5) "14.95"
["sale-price"]=>
string(3) "0.0"
["sku"]=>
string(8) "13671976"
["upc"]=>
object(SimpleXMLElement)#73 (0) {
}
}
[1]=>
object(SimpleXMLElement)#78 (19) {
["ad-id"]=>
string(8) "10450940"
["advertiser-id"]=>
string(7) "1427863"
["advertiser-name"]=>
string(12) "Bookbyte.com"
["advertiser-category"]=>
string(5) "Books"
["buy-url"]=>
string(148) "http://www.jdoqocy.com/click-4107027-10450940?url=http%3A%2F%2Fwww.bookbyte.com%2Fproduct.aspx%3Fisbn%3D1576751740%26noredirect%3Dtrue&cjsku=1084348"
["catalog-id"]=>
string(8) "cjo:1574"
["currency"]=>
string(3) "USD"
["description"]=>
string(41) "This book is in New - Excellent condition"
["image-url"]=>
object(SimpleXMLElement)#73 (0) {
}
["in-stock"]=>
object(SimpleXMLElement)#72 (0) {
}
["isbn"]=>
string(10) "1576751740"
["manufacturer-name"]=>
object(SimpleXMLElement)#75 (0) {
}
["manufacturer-sku"]=>
object(SimpleXMLElement)#74 (0) {
}
["name"]=>
string(53) "Leadership and Self Deception: Getting Out of the Box"
["price"]=>
string(5) "11.21"
["retail-price"]=>
string(5) "14.95"
["sale-price"]=>
string(3) "0.0"
["sku"]=>
string(7) "1084348"
["upc"]=>
object(SimpleXMLElement)#77 (0) {
}
}
[2]=>
object(SimpleXMLElement)#79 (19) {
["ad-id"]=>
string(8) "10450940"
["advertiser-id"]=>
string(7) "1427863"
["advertiser-name"]=>
string(12) "Bookbyte.com"
["advertiser-category"]=>
string(5) "Books"
["buy-url"]=>
string(148) "http://www.kqzyfj.com/click-4107027-10450940?url=http%3A%2F%2Fwww.bookbyte.com%2Fproduct.aspx%3Fisbn%3D1576751740%26noredirect%3Dtrue&cjsku=12530742"
["catalog-id"]=>
string(8) "cjo:1574"
["currency"]=>
string(3) "USD"
["description"]=>
string(34) "This book is in Like New condition"
["image-url"]=>
object(SimpleXMLElement)#77 (0) {
}
["in-stock"]=>
object(SimpleXMLElement)#74 (0) {
}
["isbn"]=>
string(10) "1576751740"
["manufacturer-name"]=>
object(SimpleXMLElement)#75 (0) {
}
["manufacturer-sku"]=>
object(SimpleXMLElement)#72 (0) {
}
["name"]=>
string(53) "Leadership and Self Deception: Getting Out of the Box"
["price"]=>
string(5) "29.25"
["retail-price"]=>
string(5) "14.95"
["sale-price"]=>
string(3) "0.0"
["sku"]=>
string(8) "12530742"
["upc"]=>
object(SimpleXMLElement)#73 (0) {
}
}
[3]=>
object(SimpleXMLElement)#76 (19) {
["ad-id"]=>
string(8) "10586024"
["advertiser-id"]=>
string(7) "2172304"
["advertiser-name"]=>
string(5) "Chegg"
["advertiser-category"]=>
string(45) "Media > Books > Non-Fiction > Education Books"
["buy-url"]=>
string(116) "http://www.dpbolvw.net/click-4107027-10586024?url=http%3A%2F%2Fwww.chegg.com%2Fdetails%2F1576751740&cjsku=1576751740"
["catalog-id"]=>
string(8) "cjo:2718"
["currency"]=>
string(3) "USD"
["description"]=>
string(584) "The disease of self-deception (acting in ways contrary to what one knows is right) underlies all leadership problems in today's organizations, according to the premise of this work. However well intentioned they may be, leaders who deceive themselves always end up undermining their own performance.This straightforward book explains how leaders can discover their own self-deceptions and learn how to escape destructive patterns. The authors demonstrate that breaking out of these patterns leads to improved teamwork, commitment, trust, communication, motivation, and leadership."
["image-url"]=>
string(53) "http://c.chegg.com/covers2/10000/15246_1307127219.jpg"
["in-stock"]=>
object(SimpleXMLElement)#73 (0) {
}
["isbn"]=>
string(10) "1576751740"
["manufacturer-name"]=>
string(9) "chegg.com"
["manufacturer-sku"]=>
object(SimpleXMLElement)#72 (0) {
}
["name"]=>
string(29) "Leadership and Self-Deception"
["price"]=>
string(4) "9.99"
["retail-price"]=>
string(5) "15.95"
["sale-price"]=>
string(3) "0.0"
["sku"]=>
string(10) "1576751740"
["upc"]=>
string(13) "9781576751749"
}
}
}
}
they are Objects (SimpleXMLElement)
$result->products->product[0]->name

Categories