PHP Array built-in functions in in_array()

tutspack laravel
Spread the love

Aarray built in functions in php. Hello Programmers, In this tutorial, I will discuss with you a PHP built in function which is in_array().

The PHP in_array() function is a built-in function. in_array() function checks if a value exists or not in a array. It returns TRUE if the given items are found in the given array, and returns FALSE otherwise.

PHP in_array() Syntax

The PHP in_array() function syntax is in_array(search, array, type)

search: Required. Specifies what to search for

array: Required. it specifies the array in which we want to search.

type : Optional. If this parameter is set to TRUE, the in_array() function searches for the search-string and specific type in the array.

Example : 

  $items = array("Mobile", "TV", "Camera", "iPhone");

  return (in_array("iPhone", $items))
         ? "Yes" : "Not";

Output: Yes

Read More: 10 PHP interview Questions

More Example of PHP array (in_array) function :

$image = $_FILES['image']['name'];
        $permit = array('png','jpg','jpeg');
        $ext = explode('.',$image);
        $ext = strtolower(end($ext));
        if(in_array($ext,$permit) === false){
            echo "EXT_NOT_MATCH";
       //go for next request


Read More: laravel API CRUD with the sanctum

Hope it can help you.

Spread the love

About Anisur Rahman Shahin

Hello. My name is Shahin. I'm a tech enthusiast guy. Personally, I’m an Optimistic and always in hurry kinda person. I'm a freelance web developer. I am working at Zakir Soft as Laravel Developer. My Portfolio website:

View all posts by Anisur Rahman Shahin →

2 Comments on “PHP Array built-in functions in in_array()”

  1. Hi there, I discovered your website by the use of Google whilst searching for a
    similar subject, your site got here up, it seems great. I’ve bookmarked it
    in my google bookmarks.
    Hello there, just was alert to your blog via Google, and found that it’s really informative.
    I am gonna watch out for brussels. I will be grateful should you continue this
    in future. A lot of people will be benefited from
    your writing. Cheers!

Leave a Reply

Your email address will not be published.