Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Object Property has brackets in it

Tags:

object

php

mysql

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] => 5 [min(time)] => 13.40 )

how can I call this property? I have tried all sorts but nothing seems to work, and cannot seem to find any info on the interwebs.

Thanks very muchly!

like image 524
Chris Avatar asked Nov 23 '11 01:11

Chris


1 Answers

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.

like image 107
BoltClock Avatar answered Nov 09 '22 07:11

BoltClock