php - is isset way is faster than array_search?

Theory speaking, looking into hashmap (isset) is faster than array_search or in_array. But, let’s see how it work in php in practice. Look at this code block: function detectGender($keyword) { $gender = 0; $genderKeywords = [ 'MY' => [ 1 => 'men,male', 2 => 'women,female', ], 'SG' => [ 1 => 'men,male', 2 => 'women,female', ], 'HK' => [ 1 => 'men,male', 2 => 'women,female', ], 'PH' => [ 1 => 'men,male', 2 => 'women,female', ], 'TH' => [ 1 => 'ชาย,ผชาย', 2 => 'หญง,ผหญง', ], 'VN' => [ 1 => 'nam', 2 => 'nu', ], 'ID' => [ 1 => 'pria', 2 => 'wanita', ], ]; foreach ($genderKeywords['VN'] as $key => $keywords) { if (array_search($keyword, explode(',', $keywords)) !...

March 13, 2018 · 3 min · longka