This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 7 years ago.
I'm trying to set the post_id as a variable using the following but I'm getting an Undefined index error.
$propertyID['post_id']
This is my var_dump()
array(1) {
[0]=>
array(2) {
["post_id"]=>
string(4) "4323"
["meta_key"]=>
string(9) "unique_id"
}
}
You have to use $propertyID[0]['post_id']
All value in index 0 of array :-
$propertyID[0]['post_id'] //result :- 4323
$propertyID[0]['meta_key'] //result :- unique_id
Related
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 5 years ago.
I want to get the value of phonenumber from below json
array(1) {
["response"]=>
array(2) {
["ResponseStatus"]=>
int(1)
["numbers"]=>
array(1) {
["PhoneNumber"]=>
string(12) "6778"
}
}
}
I have tried $response['response']['numbers'][0]['PhoneNumber'] & $response['response']['numbers']->PhoneNumber
I've tried looking at your code and replicated the Array myself, if you do:
echo $array["response"]["numbers"]["PhoneNumber"];
It should display the PhoneNumber value.
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
I need to get "bar" from this:
array(1) { [1]=> array(2) { ["id"]=> string(4) "8097" ["content"]=> string(3) "bar" } }
Is there any way to do it? (the code is from var_dump).
Since I don't know why you want "bar" specifically (i.e., is it just the 'content' of the element with index [1]?) I'll suggest simply:
echo $your_array[1]['content'];
try array_search('what you want to search','Where you want to search')
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 7 years ago.
This is my array:
array(3) {
["formData"]=>
array(25) {
["Contact.Name.First"]=>
object(stdClass)#17 (2) {
["value"]=>
string(31) "POLIANA KRUSCHER PISCOLLE"
["required"]=>
bool(true)
}
["Contact.CustomFields.c.new_cpf"]=>
object(stdClass)#21 (2) {
["value"]=>
string(14) "038.889.971-99"
["required"]=>
bool(true)
}
}
How can I retrieve value in Contact.CustomFields.c.new_cpf?
I tried $incident_data['Contact.CustomFields.c.new_cpf']['value'], but it returns null.
Try this way:
$incident_data['formData']['Contact.CustomFields.c.new_cpf']->value;
Your $incident_data['formData']['Contact.CustomFields.c.new_cpf'] does not contain an array yet you try to access it as such.
Since there is no such key php defaults to null. (Yet there also should be an undefined index notice thrown around. You may want to enhance your error logging / strictness level).
As by your dump you have an of the \stdClass class, you have to treat them as such:
$object->value
This question already has answers here:
Return PHP object by index number (not name)
(5 answers)
Closed 7 years ago.
How do I access the following stdclass, and echo Transaction ID has already been used.
object(stdClass)#2 (1) {
["SendBulkSMS_PHPResult"]=>
object(stdClass)#3 (1) {
["string"]=>
array(3) {
[0]=>
string(1) "0"
[1]=>
string(37) "Transaction ID has already been used."
[2]=>
NULL
}
}
}
From the look of it, it would be:
$object->SendBulkSMS_PHPResult->string[1];
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 7 years ago.
Just a real quick question please, I have this string that came from my query
I am able to display the string using xx = dd($sumx) which gave me the string below:
string(124) "[{"total":-4107717.58,"alerx":4,"currentYear":-4107717.58,"lastYear":0,"date":2015,"value":{"debit":0,"credit":4107717.58}}]"
in order for me to access it via '->' notation, like an object. I convert it using json_decode()
I echoed it again and gives me this object format:
array(1) {
[0]=>
object(stdClass)#508 (6) {
["total"]=>
float(-4107717.58)
["alerx"]=>
int(4)
["currentYear"]=>
float(-4107717.58)
["lastYear"]=>
int(0)
["date"]=>
int(2015)
["value"]=>
object(stdClass)#509 (2) {
["debit"]=>
int(0)
["credit"]=>
float(4107717.58)
}
}
}
when I tried to access $sumx->value it then gives me a `Trying to get property of non-object
I tried accessing it via $sumx[0]->value same error, I also tried validating the string to http://jsonlint.com/ and it says its valid. Can someone point out to me whats wrong please. Thanks for the time and have a good day.
Try like below:-
<?php
$data = '[{"total":-4107717.58,"alerx":4,"currentYear":-4107717.58,"lastYear":0,"date":2015,"value":{"debit":0,"credit":4107717.58}}]';
$new_array = json_decode($data);
echo "<pre/>";print_r($new_array);
echo "<pre/>";print_r($new_array['0']->value);
echo "<pre/>";print_r($new_array['0']->value->debit);
echo "<pre/>";print_r($new_array['0']->value->credit);
?>
Output:- https://eval.in/381395
Note:- change is $new_array['0']->value only.