get value within object in an array
up vote
0
down vote
favorite
I have an array, containing an object. I need the value of a property of the first object but somehow I get an empty value.
My array $params
(from print_r) looks like this:
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
Cut off here, there are two more objects in this array.
Now if I do: echo $params[0]->name
I get an empty result.
Also tried print_r($params[0], true);
, empty result.
Also tried, empty result:
$status = $params[0];
echo $status->name;
What am I doing wrong here?
Thanks in advance
php arrays object prestashop
add a comment |
up vote
0
down vote
favorite
I have an array, containing an object. I need the value of a property of the first object but somehow I get an empty value.
My array $params
(from print_r) looks like this:
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
Cut off here, there are two more objects in this array.
Now if I do: echo $params[0]->name
I get an empty result.
Also tried print_r($params[0], true);
, empty result.
Also tried, empty result:
$status = $params[0];
echo $status->name;
What am I doing wrong here?
Thanks in advance
php arrays object prestashop
3
There is no0
index in$params
. The only index I can see isnewOrderStatus
.
– Sergiu Paraschiv
Nov 8 at 10:29
1
Try$params['newOrderStatus']->name
– The fourth bird
Nov 8 at 10:29
Also duplicate of: stackoverflow.com/questions/1921421/…
– k0pernikus
Nov 8 at 10:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an array, containing an object. I need the value of a property of the first object but somehow I get an empty value.
My array $params
(from print_r) looks like this:
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
Cut off here, there are two more objects in this array.
Now if I do: echo $params[0]->name
I get an empty result.
Also tried print_r($params[0], true);
, empty result.
Also tried, empty result:
$status = $params[0];
echo $status->name;
What am I doing wrong here?
Thanks in advance
php arrays object prestashop
I have an array, containing an object. I need the value of a property of the first object but somehow I get an empty value.
My array $params
(from print_r) looks like this:
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
Cut off here, there are two more objects in this array.
Now if I do: echo $params[0]->name
I get an empty result.
Also tried print_r($params[0], true);
, empty result.
Also tried, empty result:
$status = $params[0];
echo $status->name;
What am I doing wrong here?
Thanks in advance
php arrays object prestashop
php arrays object prestashop
edited Nov 8 at 10:30
Mickael Leger
2,3881726
2,3881726
asked Nov 8 at 10:28
IJsbrand Schipperus
33
33
3
There is no0
index in$params
. The only index I can see isnewOrderStatus
.
– Sergiu Paraschiv
Nov 8 at 10:29
1
Try$params['newOrderStatus']->name
– The fourth bird
Nov 8 at 10:29
Also duplicate of: stackoverflow.com/questions/1921421/…
– k0pernikus
Nov 8 at 10:32
add a comment |
3
There is no0
index in$params
. The only index I can see isnewOrderStatus
.
– Sergiu Paraschiv
Nov 8 at 10:29
1
Try$params['newOrderStatus']->name
– The fourth bird
Nov 8 at 10:29
Also duplicate of: stackoverflow.com/questions/1921421/…
– k0pernikus
Nov 8 at 10:32
3
3
There is no
0
index in $params
. The only index I can see is newOrderStatus
.– Sergiu Paraschiv
Nov 8 at 10:29
There is no
0
index in $params
. The only index I can see is newOrderStatus
.– Sergiu Paraschiv
Nov 8 at 10:29
1
1
Try
$params['newOrderStatus']->name
– The fourth bird
Nov 8 at 10:29
Try
$params['newOrderStatus']->name
– The fourth bird
Nov 8 at 10:29
Also duplicate of: stackoverflow.com/questions/1921421/…
– k0pernikus
Nov 8 at 10:32
Also duplicate of: stackoverflow.com/questions/1921421/…
– k0pernikus
Nov 8 at 10:32
add a comment |
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
You need to access object as following
$params['newOrderStatus'];
In above object you will have all child objects so you can access them by following
$params['newOrderStatus']->name;
$params['newOrderStatus']->template;
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
add a comment |
up vote
2
down vote
Well, as you said your array looks like this :
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
So there is no $param[0]
, you should do $param['newOrderStatus']
and then get what you want : $param['newOrderStatus']->name
add a comment |
up vote
1
down vote
Your array $params
has a key called newOrderStatus
which has the object as a value you are looking for.
Looking at your example, there is value for index 0.
To get the value of the name property, you could use:
$params['newOrderStatus']->name
add a comment |
up vote
0
down vote
You can type cast it to an array like this:
$array = (array) $yourObject;
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to access object as following
$params['newOrderStatus'];
In above object you will have all child objects so you can access them by following
$params['newOrderStatus']->name;
$params['newOrderStatus']->template;
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
add a comment |
up vote
1
down vote
accepted
You need to access object as following
$params['newOrderStatus'];
In above object you will have all child objects so you can access them by following
$params['newOrderStatus']->name;
$params['newOrderStatus']->template;
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to access object as following
$params['newOrderStatus'];
In above object you will have all child objects so you can access them by following
$params['newOrderStatus']->name;
$params['newOrderStatus']->template;
You need to access object as following
$params['newOrderStatus'];
In above object you will have all child objects so you can access them by following
$params['newOrderStatus']->name;
$params['newOrderStatus']->template;
answered Nov 8 at 10:32
Ayaz Shah
1,97511645
1,97511645
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
add a comment |
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
Thanks! Somehow I thought I had tried this also, but I was probably lost in trying to much.
– IJsbrand Schipperus
Nov 8 at 10:34
add a comment |
up vote
2
down vote
Well, as you said your array looks like this :
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
So there is no $param[0]
, you should do $param['newOrderStatus']
and then get what you want : $param['newOrderStatus']->name
add a comment |
up vote
2
down vote
Well, as you said your array looks like this :
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
So there is no $param[0]
, you should do $param['newOrderStatus']
and then get what you want : $param['newOrderStatus']->name
add a comment |
up vote
2
down vote
up vote
2
down vote
Well, as you said your array looks like this :
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
So there is no $param[0]
, you should do $param['newOrderStatus']
and then get what you want : $param['newOrderStatus']->name
Well, as you said your array looks like this :
Array
(
[newOrderStatus] => OrderState Object
(
[name] => Canceled
[template] => order_canceled
[send_email] => 1
...
So there is no $param[0]
, you should do $param['newOrderStatus']
and then get what you want : $param['newOrderStatus']->name
answered Nov 8 at 10:32
Mickael Leger
2,3881726
2,3881726
add a comment |
add a comment |
up vote
1
down vote
Your array $params
has a key called newOrderStatus
which has the object as a value you are looking for.
Looking at your example, there is value for index 0.
To get the value of the name property, you could use:
$params['newOrderStatus']->name
add a comment |
up vote
1
down vote
Your array $params
has a key called newOrderStatus
which has the object as a value you are looking for.
Looking at your example, there is value for index 0.
To get the value of the name property, you could use:
$params['newOrderStatus']->name
add a comment |
up vote
1
down vote
up vote
1
down vote
Your array $params
has a key called newOrderStatus
which has the object as a value you are looking for.
Looking at your example, there is value for index 0.
To get the value of the name property, you could use:
$params['newOrderStatus']->name
Your array $params
has a key called newOrderStatus
which has the object as a value you are looking for.
Looking at your example, there is value for index 0.
To get the value of the name property, you could use:
$params['newOrderStatus']->name
edited Nov 8 at 10:49
answered Nov 8 at 10:31
The fourth bird
18k71323
18k71323
add a comment |
add a comment |
up vote
0
down vote
You can type cast it to an array like this:
$array = (array) $yourObject;
add a comment |
up vote
0
down vote
You can type cast it to an array like this:
$array = (array) $yourObject;
add a comment |
up vote
0
down vote
up vote
0
down vote
You can type cast it to an array like this:
$array = (array) $yourObject;
You can type cast it to an array like this:
$array = (array) $yourObject;
answered Nov 8 at 10:31
Aravind Bhat K
13112
13112
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205835%2fget-value-within-object-in-an-array%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
There is no
0
index in$params
. The only index I can see isnewOrderStatus
.– Sergiu Paraschiv
Nov 8 at 10:29
1
Try
$params['newOrderStatus']->name
– The fourth bird
Nov 8 at 10:29
Also duplicate of: stackoverflow.com/questions/1921421/…
– k0pernikus
Nov 8 at 10:32