I have a some data stored in $cache[], there are some number in it. How do I remove duplicate values in a printed output? :
<?
#mysql connect
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($name) or die(mysql_error());
function get_numerics ($str) {
preg_match_all('/\d+/', $str, $matches);
return $matches[0];
}
function validatecard($number) {
//preg_match_all('/^[6-9][0-9]{9}$/', $number, $found);
preg_match_all('/^[0-9]{4}$/',$number, $found);
//print_r($found);
return $found[0];
}
$query = mysql_query("SELECT * FROM client WHERE status = 1 ORDER BY id")
or die(mysql_error());
while ($raw = mysql_fetch_array($query))
{
$name = $raw["postdata"];
$id = $raw["id"];
$cache = [];
for($i=0;$i<=count(get_numerics($name));$i++){
$ccv = get_numerics($name);
$num = $ccv[$i];
if (is_numeric($num)) {
$cc = validatecard($num);
if (!in_array($cc, $cache)){
$cache[] = $cc;
}
}
}
print_r($cache);
}
?>
i have use some function like :array unique and convert it to json or serialize... and not work.