Ninjakreborn Posted August 16, 2012 Share Posted August 16, 2012 This might be...easier than i'm trying to make it. For some reason it's failing me. Array ( [0] => stdClass Object ( [player_id] => 11 [orders] => 5 [q1Points] => 110.75 [q2Points] => 109 [q3Points] => 0 [q4Points] => 36 [total_points] => 255.75 ) [1] => stdClass Object ( [player_id] => 39 [orders] => 2 [q1Points] => 75.5 [q2Points] => 100.25 [q3Points] => 0 [q4Points] => 45.5 [total_points] => 221.25 ) [2] => stdClass Object ( [player_id] => 38 [orders] => 1 [q1Points] => 63 [q2Points] => 70 [q3Points] => 0 [q4Points] => 83.25 [total_points] => 216.25 ) [3] => stdClass Object ( [player_id] => 41 [orders] => 3 [q1Points] => 73.75 [q2Points] => 54 [q3Points] => 0 [q4Points] => 71 [total_points] => 198.75 ) [4] => stdClass Object ( [player_id] => 23 [orders] => 7 [q1Points] => 88.75 [q2Points] => 59 [q3Points] => 0 [q4Points] => 43.125 [total_points] => 190.875 ) [5] => stdClass Object ( [player_id] => 37 [orders] => 4 [q1Points] => 30.25 [q2Points] => 76 [q3Points] => 0 [q4Points] => 55.875 [total_points] => 162.125 ) [6] => stdClass Object ( [player_id] => 43 [orders] => 6 [q1Points] => 44 [q2Points] => 23.25 [q3Points] => 0 [q4Points] => 39.625 [total_points] => 106.875 ) [7] => stdClass Object ( [player_id] => 44 [orders] => 8 [q1Points] => 36.25 [q2Points] => 22.5 [q3Points] => 0 [q4Points] => 32 [total_points] => 90.75 ) ) I want to find which item has the highest Q4Points value and get the player ID from it. That should be easy, but for some reason my mind is trying to make it complicated. Quote Link to comment https://forums.phpfreaks.com/topic/267179-matching-one-object-value-and-pulling-out-array/ Share on other sites More sharing options...
KevinM1 Posted August 16, 2012 Share Posted August 16, 2012 You just need a simple linear search: <?php $highestPoints = 0.0; $highestObject; foreach ($array as $val) { if ($val->Q4Points >= $highestPoints) { $highestObject = $val; $highestPoints = $val->Q4Points; } } $id = $highestObject->ID; ?> Quote Link to comment https://forums.phpfreaks.com/topic/267179-matching-one-object-value-and-pulling-out-array/#findComment-1369905 Share on other sites More sharing options...
Ninjakreborn Posted August 16, 2012 Author Share Posted August 16, 2012 Thanks, I appreciate that. Quote Link to comment https://forums.phpfreaks.com/topic/267179-matching-one-object-value-and-pulling-out-array/#findComment-1369932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.