The difference between php array_key_exists() and isset()

墨辰丷
Release: 2023-03-28 16:08:02
Original
1563 people have browsed it

This article mainly introduces relevant information about the difference between php array_key_exists() and isset(). Friends who need it can refer to it

php array_key_exists is used to check whether a key name exists in the array. Iset can also be used to detect whether a certain key name exists in an array, so what is the difference between the two? This article will explain to you some differences in the use of array_key_exists() and isset()

A basic difference is that isset() can be used for arrays and variables, while array_key_exits() can only be used for arrays.

But the main difference lies in the return value under the set conditions.

Now let’s verify this main difference.

array_key_exists()

array_key_exists() will check the existence of the key value. This function will return TRUE as long as the key value exists, even if the value is NULL.

$arr = array( "one"=>"1", "two"=>"2", "three"=>null ); 
array_key_exists("one", $arr); // true 
array_key_exists("two", $arr); // true 
array_key_exists("three", $arr); // true
Copy after login

isset()

Different from arrry_key_exitst(), isset() will check the key and value at the same time. Only when the key exists, TRUE will be returned only when the corresponding variable is not NUll.

$arr = array( "one"=>"1", "two"=>"2", "three"=>null );
isset($arr["one"]); // true 
isset($arr["two"]); // true 
isset($arr["three"]); // false
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

Detailed explanation of PHP custom image center cropping function

PHP recursively implements folder copying, deletion, viewing size, etc.

What are the ways to implement multi-dimensional array sorting algorithm in PHP

The above is the detailed content of The difference between php array_key_exists() and isset(). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template