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

Uncovering Chennai: A Traveler and Local Perspective on City Life, Events and Landmarks

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

Modernizing Tech Stacks for Scalable Gaming Enterprises

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

Essential Qualities and Competencies to Look for in a DevOps Instructor

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

Exploring Your Backyard: Finding Local Goods, Shops, and Services

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

Finding Your Way Through Oncology Care: A Patient and Family Roadmap

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

Finding Excellence in Neurological Care: Selecting a Specialized Neurosurgery Facility

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