0

How can I echo the 33 from this printed array directly?

Array (
    [0] => stdClass Object (
        [max(renr)] => 333
    )
)
5

4 Answers 4

3

$array[0]->{'max(renr)'}

Sign up to request clarification or add additional context in comments.

3 Comments

You can use the curly braces to access the value in the object.
You really should use aliases in your SQL. SELECT max(renr) AS renrMax
Yes.. PLEASE use aliases. Your PHP code will make everyone reading it hate you if you go with the ->{'max(rend)'} solution.
0

Well that's gonna depend on your language, but assuming PHP from the look of it...

$arr[0]->max(renr)

But to be far, I don't know what an index of max(renr) means

5 Comments

This is does not work. The max(x) ist the sql max() function. Maybe that helps.
$arr[0]->{'max(renr)'} You need the curly braces to access the value because of the parentheses.
@jon_darkstar: This is the syntax for a method call, and will yield a "Call to undefined method stdClass::max" fatal error.
how does an echo_r/var_dump give the value of a method call like that? a method call, for a variable argument? thats what threw me. never thought it was SQL, would've given that bracket syntax if i knew what as going on
o nevermind get it. 'max(renr)' is literally the index bc thats how it let it come back from sql right?
0

Use an alias in your SQL query so you have an alphanumeric column name in the result set. That's the only real solution.

SELECT MAX(renr) AS max_renr FROM ....

and then $arr[0]->max_renr in your php code.

Comments

0

Use [] for array and -> for objects

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.