pdo - PHP - Find max/highest value -
I have this question:
$ stmt = $ dbh- & gt; Select Round ((Expiry - UNIX_TimeStamp ()) / 86400) As the day, count (*) as xeon_users_rented by WHERE user_by =: User name group day; "); $ Stmt- & gt; bindParam (": user name ", $ userdata ['username']); $ stmt-> executed ($); $ data = $ stmt-> fetchAll ();
; Array (4) {["day"] = & gt; string (2) "27" [0] => string (2) "27" ["cnt"] => string (1) " 2 "[1] = 2 (1)" 2 "} [1] = & gt; array (4) {[" day "] = & gt; string (3)" 116 "[0] = & String (3) "116" ["cnt"] => string (1) "8" [1] => string (1) "8"}
< P> Then I have the highest value of the $ data result I want to receive: echo max ($ data ["day"]);
Althoug which does not work, because nothing What is I doing?
$ data ['day']
isn is not an array. You have an array, each of which has its own 'day' element.
You can map your 'day' elements into an array and then click on You can get maximum ()
. :
echo max (array_map (function ($ d) {return $ d ['day'];}, $ data));
Comments
Post a Comment