How to Grab stdClass Object Result [duplicate] - php

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
can i ask ? . I have class cURL POST into a website ( API Integration ) , and if i post with class. The result is (i use print_r) :
stdClass Object
(
[order] => 200029
)
1
How to grab [order] value?

You can use:
$yourVar->order;

Related

Retrieve value from array in PHP [duplicate]

This question already has answers here:
Get values stdClass Object PHP
(1 answer)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 6 years ago.
If I have a array formatted as below
[
{
'id':1,
'some_int': 3,
'foo':'bar'
}
]
How can I retrieve, for example, 'bar' value?
If I write
$array[0]['bar']
It throws Cannot use object of type stdClass as array
If I write
$array['bar']
It throws Unidentified index: bar

php Multidimensional Array - Undefined offset / index [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
I have an array that holds a number of arrays. I access them in turn e.g.
print_r($orderData[0]) and the output is:
Array (
[201] => Array (
[name] => SuperMarket One
[type] => line_item
[item_meta] => Array (
[_qty] => Array (
[0] => 1
)
)
)
)
My issue is, I can't seem to access anything e.g. print_r($orderData[0]['name']) gives me:
Notice: Undefined index: name in /Path
Likewise, I can't use print_r($orderData[0][0]) etc.
I must be missing something quite obvious here.
You have another array in it with the key 201. Use PHP's function var_dump($orderData[0]) to view the complete structure of your array.
Access it using
$orderData[0][201]['name']

Failed to get an object property that containing ":protected" [duplicate]

This question already has answers here:
What is the difference between public, private, and protected?
(16 answers)
Closed 9 years ago.
I used the code below to get the object's property _items:protected, but no luck.
$obj = JSite::getMenu();
print_r($obj->_items:protected);
Object output
JMenuSite Object
(
[_items:protected] => Array
(
[101] => stdClass Object
(
[id] => 101
[menutype] => mainmenu
Anyone know what wrong with my code? Thanks.
You are trying to access a protected property from outside the class.
A protected property can only be accessed from within the class itself or classes that inherit from that class.
Read up on OOP access modifiers.

Getting an item with a # from an stdClass [duplicate]

This question already has answers here:
Special characters in property name of object
(2 answers)
Closed 9 years ago.
When I do a print_r($this->info->artist->image[4]);, I get this:
stdClass Object
(
[#text] => http://userserve-ak.last.fm/serve/_/68145708/AWOLNATION+PNG.png
[size] => mega
)
How do I get the [#text] part?
You would do:
$this->info->artist->image[4]->{'#text'};
$this->info->artist->image[4]->{'#text'};

reference object with key containing brackets [duplicate]

This question already has answers here:
PHP Object Property has brackets in it
(2 answers)
Closed 9 years ago.
I'm doing a print_r on an object that is returned after running a query. Here is my print_r log.
stdClass Object
(
[MAX(sort_order)] => 3
)
I want to get the value inside [MAX(sort_order)] but I cant figure out how to target it from within php.
Like $sort_order = $object->[MAX(sort_order)]; (I know that won't work)
Does anyone know how I can do this?
Try add this in your query MAX(sort_order) AS max_sort_order in your query

Categories