How to remove the key value (value) of a one-dimensional array in php

青灯夜游
Release: 2023-03-14 07:18:02
Original
2524 people have browsed it

In PHP, you can use the array_keys() function to remove the key value (value) of a one-dimensional array, leaving only the key name (key) of the array. The syntax format is "array_keys($array)".

How to remove the key value (value) of a one-dimensional array in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, each element of the array It is composed of key-value pairs, and the value of the corresponding key is accessed through the key name of the element.

提示:“索引”和“键名”指的是同一样东西,“索引”多指数组数字形式的下标。
Copy after login

Sometimes, we need to remove the key value (value) of a one-dimensional array and leave only the key name (key) of the array. How to do this?

At this point, you can use the array_keys() function.

array_key() function can obtain some or all key names in the array. The syntax format is as follows:

array_keys($array [, $search_value = null [, $strict = false]])
Copy after login

The parameter description is as follows:

  • $array: required Parameter is the array to be operated;
  • $search_value: optional parameter. If the parameter is empty, the function will return all key names in the array. If this parameter is specified, the function will only return the value. is the key name of $search_value;
  • $strict: optional parameter to determine whether to use strict mode when searching. $strict defaults to false, which is non-strict mode. Only types are compared when searching, not Compare types. If $strict is set to true, it is strict mode. The value and type are compared at the same time during search, which is equivalent to===.

array_key() function will return the obtained array key name in the form of an array.

 'PHP中文网', 'url' => '//m.sbmmt.com/', 'title' => 'PHP教程', ); $key=array_keys($array); var_dump($key); ?>
Copy after login

How to remove the key value (value) of a one-dimensional array in php

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.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove the key value (value) of a one-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!