0
Next I’m with the system to make a history on a site, it saves the id of the page that the user visited, separating the id by comma.
Would it be possible to limit the value to 30 ? example "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30".
And when this value exceeds it begin to update the older ones by replacing the values in descending order? example: "1,2,3.... 29,53"
$id = $_COOKIE["id"];
$novoId = "$cont[id]";
if (!preg_match("/\b{$novoId}\b/", $id)) {
setcookie("id", $id .= "{$novoId},");
}
$historico = explode(",", $id);
$histanime = array_filter($historico, function($value) {
/* Retorna apenas os números inteiros */
return is_numeric($value);
});
$ids5 = implode(",", $histanime) ;
if you want to consider the full code, I’ve added it
– Gabriel
@Gabriel, I made the changes.
– Inkeliz
I added if(($quantity = Count($historico)) > 30){ $historico = array_slice($historico, $quantidade - 30, 30); } to the original code and had the same effect.
– Gabriel