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.

user3673405
  • 33
  • 1
  • 8

1 Answers1

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;
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87