PHP check duplicate values in an array and return it

How to check duplicate values in an array and return it using PHP?Also telling php check wild card value in an array and return those values.For a example you want to check number of times that values exist and return that all values in an array.Check this example, you can understand this better.

// This is the array
$Keywords = array("One","three","four","one","two", "one");

//convert to lowercase
$Keywords = array_map('strtolower', $Keywords);

// query for search the value
$char = trim($_GET['q']);

if(ctype_upper($char)) // if first character uppercase,
$char = strtolower($_GET['q']); // then convert to lowercase

//Checking wild card values
function in_array_wildcard( $needle, $arr )
return array_values( preg_grep( '/' . str_replace( '*', '.*', $needle ) . '/', $arr ) );

// call to the function
$duplicateArr = in_array_wildcard( $char, $Keywords );

Published by

Sumith Harshan

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.