1

I have script which needs to find the star performer of the month.

This is sample data

 $data = array (
 [0] = array(
 "tasks_done" => 5,
 "rating" => 5),
 [1] = array(
 "tasks_done" => 4,
 "rating" => 5),
 [2] = array(
 "tasks_done" => 3,
 "rating" => 5),
 [3] = array(
 "tasks_done" => 5,
 "rating" => 5)
 );

So the question is to find the person with max tasks done and max number of rating. Is this possible using any algorithm of by simple php code.

References Sample to find max number in array :

find max() of specific multidimensional array value in php

But nothing seems to work. Any help is appreciated.

asked Jun 23, 2017 at 9:36
13
  • 1
    Can you make your question clear? Commented Jun 23, 2017 at 9:39
  • Which hold more weight when comparasion??? Or your want to find max separately? Commented Jun 23, 2017 at 9:40
  • @KrisRoofe find max separately with two filters findmax(task_done) and findmax(rating) which must output one result Commented Jun 23, 2017 at 9:44
  • max(array_column($array, 'tasks_done')) Commented Jun 23, 2017 at 9:46
  • 1
    Make an effort and try something. Just coming here and waiting for a code is a bad approach. Commented Jun 23, 2017 at 9:56

2 Answers 2

0

I have sort by rating first and second tasks_done.

Please check below code,

$data = array();
$data[0]=array("tasks_done" => 5,"rating" => 5);
$data[1]=array("tasks_done" => 4,"rating" => 5);
$data[2]=array("tasks_done" => 3,"rating" => 3);
$data[3]=array("tasks_done" => 5,"rating" => 6);
$data[4]=array("tasks_done" => 6,"rating" => 2);
$data[5]=array("tasks_done" => 3,"rating" => 6);
$temp_array = array();
$output = array();
foreach($data as $k=>$values){
 $temp_array['tasks_done'][$values['tasks_done']][$k]=$values['tasks_done'];
 $temp_array['rating'][$values['rating']][$k]=$values['rating'];
}
echo "<pre>";
print_r($data);
krsort($temp_array['tasks_done']);
krsort($temp_array['rating']);
foreach($temp_array['rating'] as $k=>$v){
 $check = checkUpper($v,$temp_array['tasks_done']);
 foreach($v as $k1=>$v1){
 $output[]=array(
 "tasks_done"=>$check[$k1],
 "rating"=>$v1
 );
 }
}
function checkUpper($array_check,$array){
 $tmp = array();
 foreach($array as $keys=>$values){
 foreach($values as $key=>$value){
 if(array_key_exists($key,$array_check)){
 $tmp[$key]=$value;
 }
 }
 }
 arsort($tmp);
 return $tmp;
}

Output,

Array
(
 [0] => Array
 (
 [tasks_done] => 5
 [rating] => 6
 )
 [1] => Array
 (
 [tasks_done] => 3
 [rating] => 6
 )
 [2] => Array
 (
 [tasks_done] => 5
 [rating] => 5
 )
 [3] => Array
 (
 [tasks_done] => 4
 [rating] => 5
 )
 [4] => Array
 (
 [tasks_done] => 3
 [rating] => 3
 )
 [5] => Array
 (
 [tasks_done] => 6
 [rating] => 2
 )
)
answered Jun 23, 2017 at 10:36
0

I solved it using mysql with order by parameter. Thank you folks for your help.

answered Jun 23, 2017 at 12:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.