這裏的交易是我有一個包含17個元素的數組。我想在一定時間內獲取我需要的元素,並將它們從數組中永久刪除。更好的方法來取消設置多個數組元素
下面的代碼:
$name = $post['name'];
$email = $post['email'];
$address = $post['address'];
$telephone = $post['telephone'];
$country = $post['country'];
unset($post['name']);
unset($post['email']);
unset($post['address']);
unset($post['telephone']);
unset($post['country']);
是代碼是醜陋的,沒必要抨擊。我如何讓這看起來更好?
[array_diff_key()](http:// php。net/manual/en/function.array-diff-key.php)是一個不錯的解決方案。以爲我會補充說,你可以使用[array_intersect_key()](http://php.net/manual/en/function.array-intersect-key.php)做相反的事情,只保留某些元素 – batfastad
我與bbradley - array_diff_key是很好的解決方案 – Michael