Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
拥有一组值并将其转换为一组键的最有效方法是什么?我真的很想避免任何 foreach 循环......
$in = array( 'red', 'green', 'blue' );
进入
$out = array( 'red' => NULL, 'green' => NULL, 'blue' => NULL );
使用 PHP 的array_flip函数。
array_flip
array_fill_keys
$out = array_fill_keys($in, null);