0

I have the following code returned by print_r. Return values I need to take the number nine and pass it to a variable.

My question is, how do I take that nine put it into a variable?

Array ( [0] => stdClass Object ( [MAX(userID)] => 9 ) )

Thank you for you reply.

1
  • 4
    PROTIP: In your SQL, you can do MAX(userID) AS value. Commented Feb 12, 2016 at 17:56

1 Answer 1

4

You need curly braces with the parentheses in there:

$var = $row[0]->{'MAX(userID)'};

But as Rocket Hazmat states in the comments, just use AS to name it in the query:

SELECT MAX(userID) AS top FROM table

Then it's simpler:

$var = $row[0]->top;
Sign up to request clarification or add additional context in comments.

2 Comments

i appreciate, i face the same problem and solve like this way.
Thank you all, i solved my isue... Thank you very much

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.