Monday, March 20, 2017

Get the best Logic in tow array

I have thow data array .

$data_arr = array(
       0 =>array(
           "id" => "nis-0",
           "name" =>"nam1-0",
           "age"=>11
       ),
       1 =>array(
           "id" => "nis-1",
           "name" =>"nama-1",
           "age"=>15
       ),
       2 =>array(
           "id" => "nis-2",
           "name" =>"nama-2",
           "age"=>10
       ),
       3 =>array(
           "id" => "nis-3",
           "name" =>"nama-3",
           "usia"=>13
       ),
       4 =>array(
           "id" => "nis-4",
           "name" =>"nama-4",
           "age"=>14
       )
   );

$filter_data = ['nis-1','nis-2'];

I need to get average age has in $filter data . in this case should be get result average: (15 + 10 )/2 = 12.5

Oh yeah and then I have 1 million of data in the data $data_arr and 100 in $filter_data. and the script would have to walk less than 2 minutes . I need the best logic to execute



via jrpikong

Advertisement