PHP object has brackets

Hope this is a very simple question for you. I have a PHP object, one of the properties has brackets in it (from the MIN mysql command):

stdClass Object ( [uid] => 5 [min(time)] => 13.40 ) 

How can I name this property? I tried all kinds, but nothing works, and can't seem to find any information on interwebs.

Many thanks!

+7
source share
2 answers

you can modify the select statement to give the field aliases:

 ex. SELECT min(time) as min_time.... 

then your returned object should have the same indexation as $ obj-> min_time.

Hope this helps.

+10
source

To directly answer your question, use braces around the property name as a string:

 $row->{'min(time)'} 

The best idea is to give your aggregate value an alias in your SQL, as mentioned by other answers, then access the property using that alias. Defining an alias also gives you the ability to provide a more meaningful name than just invoking some aggregate function in a particular column or value.

+11
source

All Articles