Tools, FAQ, Tutorials:
Verifying If a Key Exists in an Array in PHP
How Do You Know If a Key Is Defined in an Array in PHP?
✍: FYIcenter.com
There are two functions can be used to test if a key is defined in an array or not:
Here is a PHP example script:
<?php 
$array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java");
print("Is 'One' defined? ".array_key_exists("One", $array)."\n");
print("Is '1' defined? ".array_key_exists("1", $array)."\n");
print("Is 'Two' defined? ".isset($array["Two"])."\n");
print("Is '2' defined? ".isset($array[2])."\n");
?>
This script will print:
Is 'One' defined? 1 Is '1' defined? Is 'Two' defined? 1 Is '2' defined?
⇒ Finding a Given Value in an Array in PHP
⇐ Counting the Number of Values in an Array in PHP
2017-01-29, ∼1953🔥, 0💬
Popular Posts:
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How to Install Docker Desktop on Windows 10? You can follow this tutorial to Install Docker Desktop ...
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...