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";
exit();
}else{
//go for next request
}
Reference:
http://php.net/manual/en/function.in-array.php
Read More: laravel API CRUD with the sanctum
Hope it can help you.
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!
thanks