How to convert a simple array to an associative array?
问题 What is the fastest way to convert a simple array to an associative array in PHP so that values can be checked in the isset($array[$value]) ? I.e. fastest way to do the following conversion: $array = array(1, 2, 3, 4, 5); $assoc = array(); foreach ($array as $i => $value) { $assoc[$value] = 1; } 回答1: array_flip() is exactly doing that: array_flip() returns an array in flip order, i.e. keys from trans become values and values from trans become keys. Note that the values of trans need to be