Showing posts with label PHP Array in Array. Show all posts
Showing posts with label PHP Array in Array. Show all posts

Wednesday, 3 June 2015

PHP: Array in Array

 A Simple function see if an array is contained within another array
<?php
function array_in_array($needle, $haystack) {
 if(count($haystack) > 0) {
  foreach ($haystack as $key => $value) {
   if ($needle == $value)
    return true;
  }
 }
 
 return false;
}
?>
 

Usage

Pass the array you want to check for and the array you want to search for it in as $needle and $haystack respectively