15 1 0 4000 1 https://codeblock.co.za 300 true 0
theme-sticky-logo-alt

array_key_exists()

0 Comments

Programming Language

PHP [Versions: 4 >= 4.0.7, 5, 7, 8]

Syntax

Typical Usage

Checks if a key or index exists in a PHP array.

Accepted Parameters

  • key (string or integer) (Required): The key or index to look for.
  • array (array) (Required): The array you wish to check.

Return Value(s)

Returns true on success or false on failure.

Notes

array_key_exists() will only search the first dimension of multidimensional arrays. 

Examples of array_key_exists()

Example 1

<?php
$cats = array('lions' => 5, 'tigers' => 4, 'leopards' => '8');
if (array_key_exists('tigers', $cats)) {
     echo 'This zoo has ' . $cats['tigers'] . ' tigers.';
}

The above will output “This zoo has 4 tigers.” because the $cats array does have a ‘tigers’ key.

Was This Helpful?

Previous Post
round()
Next Post
isset()

0 Comments

Leave a Reply