This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I know this question has been asked before.
but whenever I try to get the value of my array it does not work, only difference I can see is the name of a value is a number?
$returnValue = json_decode('{"content": [{"id": 1249029}]}');`
That gives me an array that looks like:
stdClass::__set_state(array(
'content' =>
array (
0 =>
stdClass::__set_state(array(
'id' => 1249029,
)),
),
))
So getting my id should be as simple as:
var_dump($returnValue['content']->0->id);
This code gives me an error 500.
Thanks,
You need to access it like this:
$returnValue->content[0]->id;
Related
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 4 years ago.
I know this question sounds silly, and seems like a duplicate to the other questions, but I can almost assure you it is not a duplicate.
I am getting an issue from PHP:
Notice: Undefined index: content in FILE_PATH on line 21
Line 21: echo htmlentities($about['content']);
I know for sure that $about['content'] is set because for debugging, I have
print_r($about)
Which gives me
Array
(
[0] => Array
(
[id] => 1
[page] => About Us
[content] => I have stuff here.... content for test purpose.
)
)
Any help is appreciated.
Thanks
Edit
This question is not duplicate because all the answers to the other questions don't talk about array of array. Please do not mark this question as duplicate.
From your print_r looks like you need to correct the source, or use:
echo htmlentities($about[0]['content']);
The $about is an array of array that contains the content index. One of the solution is to use:
$about = $about[0]; // Only if you know that this is the only case.
The right way is to correct at the source, why it is not being a source array, but has another sub-array.
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 7 years ago.
I've finally figured out how to fetch data from Google Analytics to website, unfortunately output (print_r) is PHP array inside an array:
Array ( [0] => Array ( [0] => 196 ) )
I need to get the number 196 & "save" it as variable in order to use it in calculations or output it, any ideas how to achieve this?
Im looking for overall solution/principle/rule because some data is even array inside array inside array etc.
you need to grab the first array element -position 0 - and from this inner array you pick the first element - also position 0 - which is 196, Check this: PHP Fiddle - hit run to execute
// getting 196
echo $myArr[0][0];
Use this:
$newVariable = $yourArray[0][0];
echo $newVariable; //This will echo the answer.
//This answer is self explanatory.
This question already has answers here:
What kind of string is this? How do I unserialize this string? [duplicate]
(2 answers)
Closed 7 years ago.
Using Gravity Forms API code GFAPI::get_entries returns an array. Most of the values are straight forward and I have no issues accessing them. However, when it outputs the "List" field it looks like this:
[44] => a:3:{i:0;a:5:{s:7:"Address";s:17:"111 Long St";s:4:"City";s:10:"Southfield";s:5:"State";s:2:"MI";s:3:"Zip";s:5:"48033";s:4:"Type";s:17:"House - Townhouse";}}
How would I set "111 Long St" to a variable? I will need all of the values but I'm sure I can figure it out once I have the answer to getting the Address.
Thanks!
[Edit]
So this is mostly my working code with a few changes to make it easier to read:
$search_criteria["field_filters"][] = array( "key" => "id", value => "10" );
$entries = GFAPI::get_entries( $form_id, $search_criteria );
...
$unserializeArray = unserialize($GLOBALS['entries'][0][44]);
return $unserializeArray[0]["Address"];
http://php.net/manual/en/function.unserialize.php
that's a serialized array in PHP, similar to JSON representation
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to pass an array via $_GET in php?
So I have a script which receives a $_POST with var Board[] containing an array of IDs.
I realized when adding ShareThis to the pages that folks wanting to share the result set would send an invalid link.
I definitely can add a delimited parameter to the script so ShareThis can pass
http://foo.com/bar.php?DelimitedBoard=3|4|5.
My question is whether there is a way to do this using the current Board[] var?
http://foo.com/bar.php?Board[]=3,4,5 fails. Is there a way?
Sure, just do:
http://foo.com/bar.php?Board[]=3&Board[]=4&Board[]=5
What you want to do is something like this:
http://foo.com/bar.php?Board[]=3&Board[]=4&Board[]=5
Then, if you print_r($_GET['Board']); in bar.php, you will get something like:
Array (
[0] => 3
[1] => 4
[2] => 5
)
Number array serialization is very easy. Use join(',', $Board) to form a comma-separated ID string, use explode(',', $_GET["Board"]) to get the array back.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Get Instance ID of an Object in PHP
I'm new to OOP and I have an object. If I:
var_dump($obj);
I get:
object(stdClass)[55]
public 'date' => int 1295297161
public 'id' => int 11
How can I retrieve the "55"?
As others have mentioned you can't read it, without parsing the output of var_dump. But if all you are looking for is a way to uniquely identify an object, then you should use spl_object_hash.