我是这样的数组:
Array([0] => 1,[1] => 2,[2] => 3,[3] => 3,[4] => 4,[5] => 5,[6] => 5,[7] => 6,[8] => 6,[9] => 6,[10] => 7,[11] => 8,[12] => 8,[13] => 8,[14] => 8,[15] => 9,[16] => 9,[17] => 9,[18] => 9,[19] => 9)
但我想要的结果如下:
Array([0] => 1,[1] => 2,[3] => 3,[4] => 4,[6] => 5,[9] => 6,[10] => 7,[14] => 8,[19] => 9)
这不仅消除了相同数组的值,而且显示了相同值的最后一个索引/键的值。有人可以帮帮我吗?
答案 0 :(得分:1)
答案 1 :(得分:0)
您可以使用数组操作功能
array_unique($arr);
答案 2 :(得分:0)
array_unique()
函数可以得到一个唯一的数组值。
<?php
$data=Array(1,2,3,3,4,5,5,6,6,6,7,8,8,8,8,9,9,9,9);
echo '<pre>';
print_r($data);
$ans=array_unique($data);
print_r($ans);
echo '</pre>';
?>
答案 3 :(得分:0)
<?php $arr=Array("[0]" => 1,"[1]" => 2,"[2]" => 3,"[3]" => 3,"[4]" => 4,"[5]" => 5,"[6]" => 5,"[7]" => 6,"[8]" => 6,"[9]" => 6,"[10]" => 7,"[11]" => 8,"[12]" => 8,"[13]" => 8,"[14]" => 8,"[15]" => 9,"[16]" => 9,"[17]" => 9,"[18]" => 9,"[19]" => 9);
var_dump($arr);
$newarr=array_unique($arr);
var_dump($newarr);
?>
答案 4 :(得分:0)
答案 5 :(得分:0)
$str = Array('0' => 1,'1' => 2,'2' => 3,'3' => 3,'4' => 4,'5' => 5,'6' => 5,'7' => 6,'8' => 6,'9' => 6,'10' => 7,'11' => 8,'12' => 8,'13' => 8,'14' => 8,'15' => 9,'16' => 9,'17' => 9,'18' => 9,'19' => 9);
$flag = 0;
foreach($str as $key=>$value)
{
if($flag == $value)
{
unset($str[$key-1]);
}
$flag = $value;
}
echo "<pre>";
print_r($str);