Post Details

How to Check If a Value Exists in an Array in PHP
25 Nov

How to Check If a Value Exists in an Array in PHP

Hi Guys,

In this example, I will show you the php array check value that exists. I’m going to show you how to check the value that exists in an array in PHP. I would like to show you how to check key value exists in an array in php. It's a simple example of how to check whether values exist in an array or not in PHP. you will do the following things for php Laravel check array value exists or not.

we will use the in_array() function and isset() function to check value exists or not in php array. so, let's see the simple code of how to check value exists in an array in PHP.

Example 1: index.php

<?php
$array = ['id' => 1, 'name' => 'test', 'email' => 'test@gmail.com'];
if (in_array('Hardik', $array)) {
    echo('Value is exists.');
} else {
    echo('Value is not exists.');
}
?>

Output: Value is exists.

Example 2: index.php

<?php
$array = ['id' => 1, 'name' => 'Test', 'email' => 'test@gmail.com'];
if (isset($array['name']) && $array['name'] == 'Hardik') {
    echo('Value is exists.');
} else {
    echo('Value is not exists.');
}
?>

Output: Value is exists.

I hope it can help you...

0 Comments

Leave a Comment