PHP array_key_exists() function

This function is used to check the existence of the given array index in the array. It always returns a boolean value, either TRUE or FALSE.

Syntax

array_key_exists(key_name, array);

Both parameters are required. It returns TRUE if the key exists in the array, otherwise it returns false.

Example1

<?php
    $arr = array( 'BIKE' => 'RED', 'CLOTH'=> 'BLUE', 'PURSE' => 'YELLOW');
    if(array_key_exists('CLOTH', $arr)) {
        echo 'cloth key exists in the array';
    }
    else{
        echo 'cloth key is not existing.';
    }
?>		

Example2

<?php
    $arr = array( 'BIKE' => 'RED', 'CLOTH'=> 'BLUE', 'PURSE' => 'YELLOW');
    if(array_key_exists('CYCLE', $arr)) {
        echo 'Cycle key exists in the array';
    }
    else{
        echo 'Cycle key is not existing.';
    }
?>		




Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language