How do you point to the cid and get the value?
$item->?
array(1) {
[0]=>
object(__PHP_Incomplete_Class)#4 (4) {
["__PHP_Incomplete_Class_Name"]=>
string(7) "Product"
["_param:protected"]=>
array(40) {
["pid"]=>
string(3) "540"
["cid"]=>
string(2) "22"
["sid"]=>
string(1) "1"
["tid"]=>
string(1) "9"
["sales_volume"]=>
string(1) "0"
["preorder_volume"]=>
string(1) "0"
["viewed"]=>
string(1) "0"
["weight"]=>
string(4) "0.00"
["delivery_type"]=>
string(6) "postal"
["cash_price"]=>
string(4) "0.00"
["coupon_price"]=>
string(4) "0.00"
["coupon_require"]=>
NULL
["member_price"]=>
NULL
["discount_code"]=>
NULL
["special_offer"]=>
string(1) "0"
["lan"]=>
string(13) "eng,tchi,schi"
["special_offer_price"]=>
string(4) "0.00"
["special_offer_begin"]=>
string(19) "2010-09-06 11:25:05"
["special_offer_end"]=>
string(19) "2010-09-06 11:25:05"
["bonus_point"]=>
string(1) "0"
["tax"]=>
string(4) "0.00"
["release_date"]=>
string(19) "2010-09-06 11:25:05"
["begin_datetime"]=>
string(19) "2010-07-13 14:41:26"
["end_datetime"]=>
NULL
["delivery_status"]=>
string(4) "24hr"
["stock"]=>
string(1) "0"
["status"]=>
NULL
["discon"]=>
string(1) "0"
["product_desc"]=>
string(0) ""
["model_num"]=>
string(8) "ATH-BT03"
["rating"]=>
string(0) ""
["recycle_id"]=>
array(2) {
[0]=>
string(1) "5"
[1]=>
string(2) "20"
}
}
}
["doc:private"]=>
object(DOMDocument)#5 (0) {
}
}
}
Class property _param is protected and you can't get access to this one from outside.
Try to use reflection. You can find how to make private/protected property is public here http://mark-story.com/posts/view/using-the-php-reflection-api-for-fun-and-profit. May be it helps.
Looks like a pretty weirdly mixed object.
If I'm following correctly, it's an array that contains an object that has a property named _param that is an array with the key cid.
$item[0]->_param['cid']
The _param member is declared as protected, and can only be accessed from within the class itself, or from parent or inherited classes. The way to access this variable from outside of the class is to create and call a "getter" method, which would look like:
function getCid() {
return $this->_param['cid'];
}
Related
array(2) {
[0]=>
object(stdClass)#21 (7) {
["id"]=>
string(1) "1"
["title"]=>
string(7) "cvxzcvd"
["con"]=>
string(10) "gvsdvgsdfg"
["is_important"]=>
string(1) "1"
["date"]=>
string(3) "123"
["image"]=>
string(2) "55"
["cat_id"]=>
string(1) "1"
}
[1]=>
object(stdClass)#22 (7) {
["id"]=>
string(1) "2"
["title"]=>
string(4) "fsdf"
["con"]=>
string(9) "dfdsfvfds"
["is_important"]=>
string(1) "1"
["date"]=>
string(4) "5145"
["image"]=>
string(7) "5454124"
["cat_id"]=>
string(1) "2"
}
}
I passed this array into a view
$this->load->view('home/index',$news_data);
but I wanna use the data separately.
I mean if I wanna use the second title
or the second data.
how can I express that in the view
thanks
You can go like this:-
$news_data[1]->title;
$news_data[1]->data;
Store the array into variable like
$news_data['arr'] = { } ;
,and in view file access it by $arr;
print_r($arr);
first I'm looking help from any expert here for PHP array calling. I try using var_dump but still I can't call my data. I'm really a beginner and need a lot of help. Thanks before for read my question below...
<?php var_dump($this->product->customfieldsSorted); ?>
I use that and get this array list...
array(1) {
["normal"]=>
array(1) {
[0]=>
object(stdClass)#222 (36) {
["virtuemart_custom_id"]=>
string(2) "21"
["custom_parent_id"]=>
string(1) "0"
["virtuemart_vendor_id"]=>
string(1) "1"
["custom_jplugin_id"]=>
string(1) "0"
["custom_element"]=>
string(0) ""
["admin_only"]=>
string(1) "0"
["custom_title"]=>
string(5) "Slide"
["show_title"]=>
string(1) "0"
["custom_tip"]=>
string(0) ""
["custom_value"]=>
string(0) ""
["custom_desc"]=>
string(0) ""
["field_type"]=>
string(1) "M"
["is_list"]=>
string(1) "0"
["is_hidden"]=>
string(1) "1"
["is_cart_attribute"]=>
string(1) "0"
["is_input"]=>
string(1) "0"
["layout_pos"]=>
string(0) ""
["custom_params"]=>
string(26) "width="1024"|height="400"|"
["shared"]=>
string(1) "0"
["published"]=>
string(1) "1"
["ordering"]=>
string(1) "0"
["virtuemart_customfield_id"]=>
string(3) "110"
["virtuemart_product_id"]=>
string(2) "95"
["customfield_value"]=>
string(2) "15"
["customfield_price"]=>
NULL
["customfield_params"]=>
string(25) "width="200"|height="200"|"
["fpublished"]=>
string(1) "0"
["override"]=>
string(1) "0"
["disabler"]=>
string(1) "0"
["_varsToPushParamCustom"]=>
array(2) {
["width"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
["height"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
}
["_varsToPushParamCustomField"]=>
array(2) {
["width"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
["height"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
}
["_varsToPushParam"]=>
array(2) {
["width"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
["height"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
}
["width"]=>
string(3) "200"
["height"]=>
string(3) "200"
["_xParams"]=>
string(18) "customfield_params"
["display"]=>
string(101) "<img src="/angga/images/stories/virtuemart/product/resized/marinecap_200x200.jpg" alt="marinecap" />"
}
}
Nah I want to get the:
["display"]=>
string(101) "<img src="/angga/images/stories/virtuemart/product/resized/marinecap_200x200.jpg" alt="marinecap" />"
using this:
<?php echo $this->product->customfieldsSorted->display;?>
and got nothing. Can anyone help? I have no clue. None at all. Thanks before :)
$this->product->customfieldsSorted is an array with the key "normal", you can get corresponding value: $this->product->customfieldsSorted['normal'].
$this->product->customfieldsSorted['normal'] is an array with the key 0, get its value: $this->product->customfieldsSorted['normal'][0].
$this->product->customfieldsSorted['normal'][0] is an object of stdClass, you can get value of the property display using $this->product->customfieldsSorted['normal'][0]->display.
I am having a hard time extracting a value from the following JSON object
array(3) { [0]=> object(stdClass)#1 (11) { ["Group"]=> string(2) "18" ["GroupName"]=> string(8) "Wireline" ["Region"]=> string(2) "15" ["RegionName"]=> string(8) "Atlantic" ["Province"]=> string(1) "1" ["ProvinceName"]=> string(13) "New Brunswick" ["City"]=> string(2) "11" ["CityName"]=> string(10) "Campbelton" ["Site"]=> string(2) "37" ["SiteName"]=> string(16) "Campbellton PNCT" ["Year"]=> string(4) "2016" }
[1]=> object(stdClass)#2 (5) { ["PlatformID"]=> string(1) "1" ["PlatformTag"]=> string(6) "Access" ["Rack"]=> string(24) "23" Width 36" Depth Rack" ["RackValue"]=> string(1) "2" ["Comments"]=> string(0) "" }
[2]=> object(stdClass)#3 (12) { ["Rack"]=> string(31) "23" Width 36" Depth Rack Access" ["RackValue"]=> string(1) "2" ["RackComments"]=> string(0) "" ["Manufacturer"]=> string(6) "werwer" ["Name"]=> string(6) "werwer" ["Quantity"]=> string(1) "1" ["RackUnits"]=> string(1) "1" ["Power"]=> string(1) "1" ["ActivePassive"]=> string(6) "Active" ["ACDC"]=> string(2) "AC" ["ConnectivityIDs"]=> array(1) { [0]=> string(1) "2" } ["Connectivity"]=> array(1) { [0]=> string(5) "Fiber" } } }
I am trying to extract each item in a foreach loop within PHP Above is the var_dump of the $data[0] JSON object it demonstrates what the Array item looks like.
My foreach is the following
$data = json_decode($_POST["submitdata"]);
$Forecasts = $data[0];
foreach($Forecasts as $Forecast){
echo($Forecast->PlatformID);}
but it returns nothing as a result. Can someone explain to me how to get this from the second Array in the object?
simply place the Index of the inner array along with the object as shown below. This will check for the sub item for the PlatformID and return it to the screen.
foreach($Forecasts as $Forecast){
echo($Forecast[1]->PlatformID);}
here is the obj :
array(2) {
[0]=> object(stdClass)#538 (9)
{
["term_id"]=> string(3) "152"
["name"]=> string(19) "Éducation physique"
["slug"]=> string(18) "education-physique"
["term_group"]=> string(1) "0"
["term_taxonomy_id"]=> string(3) "159"
["taxonomy"]=> string(11) "product_cat"
["description"]=> string(0) ""
["parent"]=> string(3) "123"
["count"]=> string(1) "3"
}
[1]=> object(stdClass)#540 (9)
{
["term_id"]=> string(3) "123"
["name"]=> string(5) "Sport"
["slug"]=> string(5) "sport"
["term_group"]=> string(1) "0"
["term_taxonomy_id"]=> string(3) "123"
["taxonomy"]=> string(11) "product_cat"
["description"]=> string(0) ""
["parent"]=> string(1) "0"
["count"]=> string(2) "49"
}
}
mam :
i try to get the value : [term_id] of 152. what i need it the "152" value in a variable. i try : $product_category->term_id it return "nothing"
and i try : $product_category['term_id'] it return "nothing"
How is the "proper" way to retreive value from object
thanks in advance !
If I'm reading you right, and $product_category is the entire variable, you have two objects in an array. So you'll need to tell PHP which array item you're after before trying to access the object.
Something like $product_category[0]->term_id should work.
Here is another solution :
Convert this object to an array using json_decode, then get the values from array
$array = json_decode($json_string, true);
$term_id = $array[0]['term_id'];
OR to get both values :
foreach($array as $val){
echo $val['term_id'];
}
Hello I am trying to print a specific value from an array of objects. I am trying to get a value from an array name $allPhotos with a object's property of "nme"'s value.
This is what im trying:
echo $allPhotos[0]["nme"];
this is what the array looks like:
var_dump($allPhotos);
array(2) {
[0]=> object(Photo)#1 (10) {
["product"]=> array(5) {
["PKG1"]=> string(4) "6500"
["PKG2"]=> string(4) "9500"
["8x10"]=> string(4) "1500"
["5x7"]=> string(3) "750"
["4x6"]=> string(3) "300"
}
["price"]=> NULL ["sku"]=> string(1) "1"
["nme"]=> string(5) "test1"
["dir"]=> string(51) "http://"
["status"]=> string(1) "1" ["gallery"]=> string(16) "Church Directory"
["galleryCover"]=> string(1) "0"
["family"]=> string(0) ""
["familyCover"]=> string(0) ""
}
[1]=> object(Photo)#2 (10) {
["product"]=> array(5) {
["PKG1"]=> string(4) "6500"
["PKG2"]=> string(4) "9500"
["8x10"]=> string(4) "1500"
["5x7"]=> string(3) "750"
["4x6"]=> string(3) "300"
}
["price"]=> NULL
["sku"]=> string(1) "2"
["nme"]=> string(5) "test2"
["dir"]=> string(51) "http://"
["status"]=> string(1) "1"
["gallery"]=> string(16) "Church Directory"
["galleryCover"]=> string(1) "0"
["family"]=> string(0) ""
["familyCover"]=> string(0) ""
}
}
Thanks in advance!
I believe echo $allPhotos[0]->nme; should work.