在我的代码下面。我想找到整数1的第三次出现的索引/位置
-1
答案 0 :(得分:0)
试试这个:
$arr = array(2, 3, 1, 4, 5, 6, 1, 1,10,11,12,1);
$result = [];
foreach($arr as $key => $val){
$result[$val][] = $key;
}
//count total record of $result[1] and third last index
$count = count($result[1]);
$thirdLastIndex = $count-3;
echo isset($result[1][$thirdLastIndex]) ? $result[1][$thirdLastIndex] : 'No record';