PHPisset and array_key_exists are different. When determining whether the index value of a PHP array exists, the isset and array_key_exists methods are generally used, but the values returned by the two methods are different, the following describes whether isset and array are used to determine whether the index value of a PHP array exists. the isset and array_key_exists methods are generally used, but they return different values, next I will introduce the differences between isset and array_key_exists. if you need them, refer to them.
Let's take a look at a simple example.
The code is as follows: |
|
Isset ($ a ['key']) Array_key_exists ('key', $ a) array_key_exists |
It tells you exactly whether a key exists in the array, while isset only returns whether the key value is null.
The isset function checks whether variables are set.
Format: bool isset (mixed var [, mixed var [,...])
Return value:
1. if the variable does not exist, FALSE is returned.
2. if the variable exists and its value is NULL, FALSE is also returned.
3. if the variable exists and the value is not NULL, true is returned.
4. when multiple variables are checked at the same time, TRUE is returned only when each individual item meets the previous requirement; otherwise, the result is FALSE.
Example 1
The code is as follows: |
|
$ A = array ('key1' => '20140901', 'key2' => null ); |
Use these two methods to determine the existence of the key value:
The code is as follows: |
|
Isset ($ a ['key1']); // true Array_key_exists ('key1', $ a); // true Isset ($ a ['key2']); // false Array_key_exists ('key2', $ a); // true |
Example 2
The code is as follows: |
|
$ A = array ('test' => 1, 'Hello' => NULL ); Var_dump (isset ($ a ['test'); // TRUE Var_dump (isset ($ a ['Foo'); // FALSE Var_dump (isset ($ a ['Hello'); // FALSE // 'Hello' is equal to NULL, so it is considered to be unassigned. // If you want to check the NULL key value, try the following method. Var_dump (array_key_exists ('hello', $ a); // TRUE ?> |
If the index value of the sort PHP array exists, the isset and array_key_exists methods are generally used, but the returned values of the two methods are different. next I will introduce isset and array...