PHP Object Property has brackets in it

后端 未结 2 922
再見小時候
再見小時候 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:14

    you could modify your select statement to give the field an alias like:

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

    then your returned object should have this indexed like so $obj->min_time.

    i hope this helps.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题