How to check a key exist in array? Explain with example?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

We can check a key exist or not in an array with the help of array_key_exist() function in PHP. array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist,  if we skip the key when we specify an array, an integer key is generated which starts at 0 and increases by 1 for each value.

syntax

array_key_exists(key, array)

this function takes two argument and this function returns boolean values(TRUE/FALSE), nested keys always return false value.

example1

<?php

        // with key values
		$shivam = array("shivam" => "23","ravi" => "24","abhi" => "25");
		
			if (array_key_exists("abhi",$shivam))
			{
				echo "Key exists";
			}
			else
			{
				echo "Key not exist";
			}
?> 

output

Key exists

example 2

<?php
       // with no key values
		$shivam = array("shivam","ravi","abhi");
		
			if (array_key_exists(0,$shivam))
			{
				echo "Key exists";
			}
			else
			{
				echo "Key not exist";
			}
?> 

output

Key exists

Related Posts

Finding Your Way Through Urology Hospitals, Specialist Care, and Treatment Pathways: An Educational Patient Guide

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

How to Train With a DevSecOps Trainer for Security-First DevOps

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Bihar Tourism Uncovered: An Insider’s Guide to Ancient Sights, Culture, and Local Life

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Unlocking Lucknow: Your Go-To Guide to Local Happenings, Weekend Passes & City Life

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

The Best Knee Replacement Hospitals in India: An Insider’s Guide for Patients

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Events in Kolkata: Ultimate Guide to Tickets, Shows & Things to Do

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x