1

How to get the last array value of this var_dump?

I do a var_dump on a variable ($submission) and get this:

object(stdClass)#148 (8) {
  ["sid"]=> string(3) "199" 
  ["nid"]=> string(4) "3042" 
  ["submitted"]=> string(10) "1386113448" 
  ["remote_addr"]=> string(9) "127.0.0.1" 
  ["uid"]=> string(2) "21" 
  ["name"]=> string(8) "SClosson" 
  ["is_draft"]=> string(1) "0"  
  ["data"]=> array(1) {
    [1]=> array(1) {
      [0]=> string(8) "blahblah" 
    } 
  }
}

So I need to store blahblah in a variable from the above array, but how?

Thought I could just get it by doing this: $submission['data'][1][0], but that doesn't work. How do I return blahblah from this?

5
  • 1
    us2.php.net/end Commented Dec 3, 2013 at 23:44
  • 2
    also objects are different than arrays, you are looking at an object actually... so $submission is an object and $submission->data is an array Commented Dec 3, 2013 at 23:46
  • I have also tried $submission->$data[1][0] and this doesn't give me anything... Commented Dec 3, 2013 at 23:52
  • 1
    print_r($submission->data) and post results.. Commented Dec 3, 2013 at 23:57
  • I was using the $data, instead of just data. Thanks Commented Dec 4, 2013 at 0:01

2 Answers 2

3

If you need an array, you can type cast it

$result = (array) $submission;

Or as an object, access the data as public properties

echo $submission->data[1][0];
Sign up to request clarification or add additional context in comments.

3 Comments

No, I need the value of blahblah in a variable of type string
Sorry, that actually did it. Thanks
also objects are different than arrays, you are looking at an object actually... so $submission is an object and $submission->data is an array – skrilled 25 mins ago
0

You can use array_pop if you want to get the last value of an array.

http://www.php.net/manual/en/function.array-pop.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.