PHP Object Property has brackets in it

后端 未结 2 946
再見小時候
再見小時候 2021-01-12 05:53

Hopefully a very easy question for you. I have a PHP object, one of the properties has brackets in it (from using MIN mysql command):

stdClass Object ( [uid]         


        
2条回答
  •  佛祖请我去吃肉
    2021-01-12 06:21

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

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

    A better idea, though, is to give your aggregate value an alias in your SQL as mentioned by the other answers, then access the property by that alias. Defining an alias also gives you an opportunity to supply a more meaningful name than just a call to some aggregate function on a certain column or value.

提交回复
热议问题