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

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

  • Post category:PHP
  • Post comments:1 Comment

In this example, I will show you php array check value exists. I’m going to show you about how to check value exists in array in php. I would like to show you how to check key value exists in array in php. It’s a simple example of how to check value exist in array or not in php. you will do the following things for php laravel check array value exists or not. You Can Learn How to Find Array Length in PHP

we will use 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 array in php.

How to Check If a Value Exists in an Array in PHP Example 1:

index.php

<?php

    $array = ['id' => 1, 'name' => 'Alom', 'email' => 'Alom@gmail.com'];

    if (in_array('Alom', $array)) {
        echo('Value is exists.');
    } else {
        echo('Value is not exists.');
    }

?>

Output:

Value is exists.

How to Check If a Value Exists in an Array in PHP Example 2:

index.php

<?php

    $array = ['id' => 1, 'name' => 'Alom', 'email' => 'Alom@gmail.com'];

    if (isset($array['name']) && $array['name'] == 'Alom') {
        echo('Value is exists.');
    } else {
        echo('Value is not exists.');
    }

?>

Output:

Value is exists.

I hope it can help you…

This Post Has One Comment

Leave a Reply