How Can I Use PHP to See If a Value Is in an Array?

Posted by

I’ll demonstrate how to use PHP to check if values in an array are duplicates. You understand the rationale behind PHP’s “check if array has same values” statement. We’ll explore PHP’s check for equal values in arrays. Please contact php laravel with any questions you may have about whether an array has duplicate values. I’ll then show you a clear example and a solution.

To find out if an array has duplicate values, PHP’s count() and array_unique() methods will be utilized. Let’s now examine the simple PHP code that determines whether an array has duplicate data.

Example 1:

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

OutPut:

Value is exists.

Example 2:

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

OutPut:

Value is exists.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x