i am trying to get custom option values from sales order items. i wrote a code as below
foreach ($order->getAllItems() as $item){
$productOptions = $item->getProductOptions();
foreach($productOptions as $opt){
var_dump($opt);
}
}
but i don't know ho to access single options through this array.
ex- $opt->Title
not getting anything for me
here is var dump for one item
array(7) { ["uenc"]=> string(80) "aHR0cDovL3ZhbmhhZ2UuY2FtZm9saW8uY28udWsvc2hvcC1vbmxpbmUvbG95YWx0eS1jYXJkLmh0bWw," ["product"]=> string(4) "1841" ["related_product"]=> string(0) "" ["super_attribute"]=> array(1) { [1000]=> string(5) "11160" } ["options"]=> array(13) { [1574]=> string(2) "Mr" [1575]=> string(7) "Cameron" [1576]=> string(4) "Owen" [1577]=> string(1) "6" [1578]=> string(14) "Address Line 1" [1579]=> string(14) "Address Line 2" [1580]=> string(4) "Town" [1581]=> string(6) "County" [1582]=> string(7) "B17 6AG" [1583]=> string(12) "0121 424 578" [1584]=> string(11) "07811877865" [1585]=> string(10) "19/04/1987" [1573]=> string(20) "hello#camfolio.co.uk" } ["cpid"]=> string(4) "1840" ["qty"]=> int(1) } array(13) { [0]=> array(7) { ["label"]=> string(5) "Title" ["value"]=> string(2) "Mr" ["print_value"]=> string(2) "Mr" ["option_id"]=> string(4) "1574" ["option_type"]=> string(5) "field" ["option_value"]=> string(2) "Mr" ["custom_view"]=> bool(false) } [1]=> array(7) { ["label"]=> string(10) "First Name" ["value"]=> string(7) "Cameron" ["print_value"]=> string(7) "Cameron" ["option_id"]=> string(4) "1575" ["option_type"]=> string(5) "field" ["option_value"]=> string(7) "Cameron" ["custom_view"]=> bool(false) } [2]=> array(7) { ["label"]=> string(9) "Last Name" ["value"]=> string(4) "Owen" ["print_value"]=> string(4) "Owen" ["option_id"]=> string(4) "1576" ["option_type"]=> string(5) "field" ["option_value"]=> string(4) "Owen" ["custom_view"]=> bool(false) } [3]=> array(7) { ["label"]=> string(12) "House Number" ["value"]=> string(1) "6" ["print_value"]=> string(1) "6" ["option_id"]=> string(4) "1577" ["option_type"]=> string(5) "field" ["option_value"]=> string(1) "6" ["custom_view"]=> bool(false) } [4]=> array(7) { ["label"]=> string(14) "Address Line 1" ["value"]=> string(14) "Address Line 1" ["print_value"]=> string(14) "Address Line 1" ["option_id"]=> string(4) "1578" ["option_type"]=> string(5) "field" ["option_value"]=> string(14) "Address Line 1" ["custom_view"]=> bool(false) } [5]=> array(7) { ["label"]=> string(14) "Address Line 2" ["value"]=> string(14) "Address Line 2" ["print_value"]=> string(14) "Address Line 2" ["option_id"]=> string(4) "1579" ["option_type"]=> string(5) "field" ["option_value"]=> string(14) "Address Line 2" ["custom_view"]=> bool(false) } [6]=> array(7) { ["label"]=> string(4) "Town" ["value"]=> string(4) "Town" ["print_value"]=> string(4) "Town" ["option_id"]=> string(4) "1580" ["option_type"]=> string(5) "field" ["option_value"]=> string(4) "Town" ["custom_view"]=> bool(false) } [7]=> array(7) { ["label"]=> string(6) "County" ["value"]=> string(6) "County" ["print_value"]=> string(6) "County" ["option_id"]=> string(4) "1581" ["option_type"]=> string(5) "field" ["option_value"]=> string(6) "County" ["custom_view"]=> bool(false) } [8]=> array(7) { ["label"]=> string(8) "Postcode" ["value"]=> string(7) "B17 6AG" ["print_value"]=> string(7) "B17 6AG" ["option_id"]=> string(4) "1582" ["option_type"]=> string(5) "field" ["option_value"]=> string(7) "B17 6AG" ["custom_view"]=> bool(false) } [9]=> array(7) { ["label"]=> string(16) "Telephone Number" ["value"]=> string(12) "0121 424 578" ["print_value"]=> string(12) "0121 424 578" ["option_id"]=> string(4) "1583" ["option_type"]=> string(5) "field" ["option_value"]=> string(12) "0121 424 578" ["custom_view"]=> bool(false) } [10]=> array(7) { ["label"]=> string(13) "Mobile Number" ["value"]=> string(11) "07811877865" ["print_value"]=> string(11) "07811877865" ["option_id"]=> string(4) "1584" ["option_type"]=> string(5) "field" ["option_value"]=> string(11) "07811877865" ["custom_view"]=> bool(false) } [11]=> array(7) { ["label"]=> string(13) "Date of Birth" ["value"]=> string(10) "19/04/1987" ["print_value"]=> string(10) "19/04/1987" ["option_id"]=> string(4) "1585" ["option_type"]=> string(5) "field" ["option_value"]=> string(10) "19/04/1987" ["custom_view"]=> bool(false) } [12]=> array(7) { ["label"]=> string(13) "Email Address" ["value"]=> string(20) "hello#camfolio.co.uk" ["print_value"]=> string(20) "hello#camfolio.co.uk" ["option_id"]=> string(4) "1573" ["option_type"]=> string(5) "field" ["option_value"]=> string(20) "hello#camfolio.co.uk" ["custom_view"]=> bool(false) } }
can anyone help me for get the datas from this
ex
Email Address
Date of Birth
etc....
thank you
$opt is a multidimensional array.
So if you want to access the first name, you would use:
$options=$opt['options'];
$name=$options[1575];
But this can be hard work. I really suggest you create a class (if there isn't one) and deserialize an object out of $opt.
Related
I have three keys pointing to value of type array, in those array values I have duplicate values. How can I remove them?
array(3) {
["rock"]=>
array(4) {
[0]=>
array(9) {
["id"]=>
string(1) "1"
["title"]=>
string(15) "Teleman Tickets"
["location"]=>
string(20) "Concorde 2, Brighton"
["event_date"]=>
string(10) "2017-02-20"
["event_time"]=>
string(8) "20:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "50.817321799999990"
["geo_long"]=>
string(17) "-0.12304610000001"
["tags"]=>
string(30) "rock,alternative,indie"
}
[1]=>
array(9) {
["id"]=>
string(1) "4"
["title"]=>
string(9) "Blink-182"
["location"]=>
string(25) "Motorpoint Arena, Cardiff"
["event_date"]=>
string(10) "2017-07-03"
["event_time"]=>
string(8) "18:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "51.478937400000010"
["geo_long"]=>
string(17) "-3.17172289999996"
["tags"]=>
string(14) "rock,metal"
}
[2]=>
array(9) {
["id"]=>
string(1) "8"
["title"]=>
string(5) "Ghost"
["location"]=>
string(29) "O2 Forum Kentish Town, London"
["event_date"]=>
string(10) "2017-03-26"
["event_time"]=>
string(8) "19:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "51.552197000000010"
["geo_long"]=>
string(17) "-0.14196900000002"
["tags"]=>
string(30) "rock,alternative,indie"
}
[3]=>
array(9) {
["id"]=>
string(2) "10"
["title"]=>
string(11) "Courteeners"
["location"]=>
string(39) "Emirates Old Trafford, Lancashire C.C.C"
["event_date"]=>
string(10) "2017-05-27"
["event_time"]=>
string(8) "16:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "53.456428000000000"
["geo_long"]=>
string(17) "-2.28679699999998"
["tags"]=>
string(30) "rock,alternative,indie"
}
}
["alternative"]=>
array(4) {
[0]=>
array(9) {
["id"]=>
string(1) "1"
["title"]=>
string(15) "Teleman Tickets"
["location"]=>
string(20) "Concorde 2, Brighton"
["event_date"]=>
string(10) "2017-02-20"
["event_time"]=>
string(8) "20:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "50.817321799999990"
["geo_long"]=>
string(17) "-0.12304610000001"
["tags"]=>
string(30) "rock,alternative,indie"
}
[1]=>
array(9) {
["id"]=>
string(1) "6"
["title"]=>
string(6) "Sum 41"
["location"]=>
string(23) "O2 Academy Leeds, Leeds"
["event_date"]=>
string(10) "2017-02-26"
["event_time"]=>
string(8) "19:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "53.802188400000000"
["geo_long"]=>
string(17) "-1.54713770000001"
["tags"]=>
string(21) "alternative,indie"
}
[2]=>
array(9) {
["id"]=>
string(1) "8"
["title"]=>
string(5) "Ghost"
["location"]=>
string(29) "O2 Forum Kentish Town, London"
["event_date"]=>
string(10) "2017-03-26"
["event_time"]=>
string(8) "19:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "51.552197000000010"
["geo_long"]=>
string(17) "-0.14196900000002"
["tags"]=>
string(30) "rock,alternative,indie"
}
[3]=>
array(9) {
["id"]=>
string(2) "10"
["title"]=>
string(11) "Courteeners"
["location"]=>
string(39) "Emirates Old Trafford, Lancashire C.C.C"
["event_date"]=>
string(10) "2017-05-27"
["event_time"]=>
string(8) "16:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "53.456428000000000"
["geo_long"]=>
string(17) "-2.28679699999998"
["tags"]=>
string(30) "rock,alternative,indie"
}
}
["sax"]=>
array(1) {
[0]=>
array(9) {
["id"]=>
string(1) "3"
["title"]=>
string(9) "Take That"
["location"]=>
string(22) "The SSE Hydro, Glasgow"
["event_date"]=>
string(10) "2017-05-11"
["event_time"]=>
string(8) "18:30:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "55.860156000000000"
["geo_long"]=>
string(17) "-4.28525800000000"
["tags"]=>
string(24) "pop,boy-band,sax"
}
}
}
I'm going to assume that if two bands have the same 'id' then they are identical
$unique_bands = array();
// if the master array is called bands
foreach($bands as $genre){
foreach($genre as $band){
$unqiue_bands[$band['id']] = $band;
}
}
Maybe put $unique_bands = array_values(array_filter($unique_bands)); at the end to reindex the array
You have a solution on the official documentation... A person made a simple function to do exactly what you want.
Example array:
<?php
$details = array(
0 => array("id"=>"1", "name"=>"Mike", "num"=>"9876543210"),
1 => array("id"=>"2", "name"=>"Carissa", "num"=>"08548596258"),
2 => array("id"=>"1", "name"=>"Mathew", "num"=>"784581254"),
);
?>
Function:
<?php
function unique_multidim_array($array, $key) {
$temp_array = array();
$i = 0;
$key_array = array();
foreach($array as $val) {
if (!in_array($val[$key], $key_array)) {
$key_array[$i] = $val[$key];
$temp_array[$i] = $val;
}
$i++;
}
return $temp_array;
}
?>
You will have to fix it to work your for array dimension.
Within available_options I have somehow stripped out Express when I just wanted to keep one of them?
The array looks like this
["options"]=>
array(9) {
[0]=>
array(8) {
["id"]=>
string(2) "79"
["product_id"]=>
string(2) "15"
["sku"]=>
string(9) "CSR-FTC4S"
["status"]=>
string(1) "1"
["is_default"]=>
string(1) "0"
["option_price"]=>
string(6) "35.000"
["sequence"]=>
string(4) "9999"
["available_options"]=>
array(3) {
[0]=>
array(6) {
["id"]=>
string(3) "219"
["product_options_base_id"]=>
string(2) "79"
["option_id"]=>
string(2) "16"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(19) "Five Ten C4 Stealth"
["name"]=>
string(11) "Resole Type"
["sku"]=>
string(5) "FTC4S"
["user_value"]=>
string(25) "Five Ten C4 Stealth 5.5mm"
["sequence"]=>
string(1) "0"
["status"]=>
string(1) "1"
["option_price"]=>
string(5) "0.000"
}
}
}
[1]=>
array(6) {
["id"]=>
string(3) "220"
["product_options_base_id"]=>
string(2) "79"
["option_id"]=>
string(2) "12"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(7) "Express"
["name"]=>
string(7) "Express"
["sku"]=>
string(3) "EXP"
["user_value"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["status"]=>
string(1) "1"
["option_price"]=>
string(6) "25.000"
}
}
}
[2]=>
array(6) {
["id"]=>
string(3) "221"
["product_options_base_id"]=>
string(2) "79"
["option_id"]=>
string(2) "23"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(16) "Rand Toe Patches"
["name"]=>
string(3) "RTP"
["sku"]=>
string(3) "RTP"
["user_value"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["status"]=>
string(1) "1"
["option_price"]=>
string(6) "10.000"
}
}
}
}
}
[1]=>
array(8) {
["id"]=>
string(2) "80"
["product_id"]=>
string(2) "15"
["sku"]=>
string(10) "CSR-FTONYX"
["status"]=>
string(1) "1"
["is_default"]=>
string(1) "0"
["option_price"]=>
string(6) "37.000"
["sequence"]=>
string(4) "9999"
["available_options"]=>
array(3) {
[0]=>
array(6) {
["id"]=>
string(3) "222"
["product_options_base_id"]=>
string(2) "80"
["option_id"]=>
string(2) "16"
["option_data_id"]=>
string(1) "2"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "2"
["admin_name"]=>
string(13) "Five Ten Onyx"
["name"]=>
string(11) "Resole Type"
["sku"]=>
string(6) "FTONYX"
["user_value"]=>
string(19) "Five Ten Onyx 4.5mm"
["sequence"]=>
string(1) "1"
["status"]=>
string(1) "1"
["option_price"]=>
string(5) "0.000"
}
}
}
[1]=>
array(6) {
["id"]=>
string(3) "223"
["product_options_base_id"]=>
string(2) "80"
["option_id"]=>
string(2) "12"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(7) "Express"
["name"]=>
string(7) "Express"
["sku"]=>
string(3) "EXP"
["user_value"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["status"]=>
string(1) "1"
["option_price"]=>
string(6) "25.000"
}
}
}
and my code goes like this
foreach($this->_data as &$data) {
foreach($data['options'] as &$option) {
$option['available_options'] = array_unique($option['available_options']);
}
}
It's working apart from it's stripped out the duplicates rather than showing them once?
array_unique does not work recursively, you need to go inside your array to apply it on option_data directly.
foreach($this->_data as &$data) {
foreach ($data['options'] as &$option) {
foreach ($option['available_options'] as &$available_option) {
foreach ($available_option['option_data'] as &$option_data) {
$option_data = array_unique($option_data);
}
}
}
}
This way, the last option_data looks like
'option_data' => [
[
'id' => '1',
'admin_name' => 'Express',
'sku' => 'EXP',
'sequence' => '9999',
'option_price' => '25.000'
]
]
But as you can see, the value Express only appear once, but user_value and status are removed too, because there value is 1, like id.
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.
i have an array in nested set model https://en.wikipedia.org/wiki/Nested_set_model, And i need convert the array to json parent-children with infinite levels.
Array example:
array(6) {
[0]=>
array(8) {
["title"]=>
string(5) "cat 2"
["type"]=>
string(3) "url"
["class_name"]=>
string(0) ""
["content"]=>
string(6) "value2"
["id"]=>
string(3) "128"
["lft"]=>
string(1) "1"
["rgt"]=>
string(1) "4"
["depth"]=>
string(1) "0"
}
[1]=>
array(8) {
["title"]=>
string(5) "sub 1"
["type"]=>
string(3) "url"
["class_name"]=>
string(0) ""
["content"]=>
string(6) "value1"
["id"]=>
string(3) "129"
["lft"]=>
string(1) "2"
["rgt"]=>
string(1) "3"
["depth"]=>
string(1) "1"
}
[2]=>
array(8) {
["title"]=>
string(5) "cat 1"
["type"]=>
string(3) "url"
["class_name"]=>
string(0) ""
["content"]=>
string(6) "value1"
["id"]=>
string(3) "130"
["lft"]=>
string(1) "5"
["rgt"]=>
string(2) "10"
["depth"]=>
string(1) "0"
}
[3]=>
array(8) {
["title"]=>
string(5) "sub 2"
["type"]=>
string(3) "url"
["class_name"]=>
string(0) ""
["content"]=>
string(6) "value2"
["id"]=>
string(3) "131"
["lft"]=>
string(1) "6"
["rgt"]=>
string(1) "9"
["depth"]=>
string(1) "1"
}
[4]=>
array(8) {
["title"]=>
string(5) "sub 3"
["type"]=>
string(3) "url"
["class_name"]=>
string(0) ""
["content"]=>
string(6) "value3"
["id"]=>
string(3) "132"
["lft"]=>
string(1) "7"
["rgt"]=>
string(1) "8"
["depth"]=>
string(1) "2"
}
[5]=>
array(8) {
["title"]=>
string(4) "item"
["type"]=>
string(3) "url"
["class_name"]=>
string(0) ""
["content"]=>
string(6) "value1"
["id"]=>
string(3) "133"
["lft"]=>
string(2) "11"
["rgt"]=>
string(2) "12"
["depth"]=>
string(1) "0"
}
}
json example:
[{"name":"Cat 1","value":"value1","children":[{"name":"sub 2", "value":"value2","children":[{"name":"sub 3", "value":"value 3"}]}]}, {"name":"Cat 2","value":"value 2","children":[{"name":"sub 1", "value":"value1"}]},{"name":"item","value":"value1"}]
can someone help me create a function to do the Convert?
json_encode should be the answer here http://php.net/manual/en/function.json-encode.php
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.