How to delete key values in associative arrays in PHP
This article mainly shows you "how to delete the key value in the associative array in PHP", the content is simple and clear, and I hope it can help you to solve your doubts. Let me lead you to study and learn this article "how to delete the key value in the associative array in PHP".
1. The unset () function can be used to unset keys and their values in an associative array.
/ declare the associative array $arr = array ("1" = > "plus", "2" = > "minus", "3" = > "multiply", "4" = > "divide"); / / delete key 1 and its value unset ($arr ['1']) in the associative array; / / display the array element var_dump ($arr)
2. Use the array_diff_key () function to get the difference between one or more arrays.
This function compares keys between one or more arrays and returns the difference between them.
/ declare the associative array $arr = array ("1" = > "spring", "2" = > "summer", "3" = > "autumn", "4" = > "winter",); / / remove key 1 and its value $result = array_diff_key ($arr, array_flip ((array) ['1'])) from the associative array; / / display the array element var_dump ($result) The above is all the contents of the article "how to delete key values in associative arrays in PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!