In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to remove the key value of an one-dimensional array by php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "php how to remove the key value of an one-dimensional array"!
In PHP, each element of an array is made up of key-value pairs (key-value), and the corresponding key value is accessed by the key name of the element.
Tip: "index" and "key name" refer to the same thing, the subscript in the form of multiple exponential groups of numbers.
Sometimes we need to remove the value of an one-dimensional array and leave only the key of the array. What should we do?
At this point, you can use the array_keys () function.
The array_key () function can get some or all of the key names in the array in the following syntax format:
Array_keys ($array [, $search_value = null [, $strict = false]])
The parameters are described as follows:
$array: required parameter, which is the array to be operated
$search_value: optional parameter. If the argument is empty, the function will return all the key names in the array. If this parameter is specified, the function will only return the key name with the value of $search_value
$strict: optional parameter to determine whether strict mode is used when searching. $strict defaults to false, that is, non-strict mode. When searching, only types are compared, not types. If $strict is set to true, strict mode, value and type are compared at the same time when searching, which is equivalent to = =.
The array_key () function returns the resulting array key name as an array.
As you can see, the key value (value) of the one-dimensional array is removed, and only the key name (key) of the one-dimensional array is returned.
Content extension:
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) At this point, I believe you have a deeper understanding of "how php removes the key value of an one-dimensional array". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.