我有一个数组调用newArray((;
$values = array_count_values($books);
arsort($values);
$newArray = array_keys($values);
它的数据低于
Array ( [0] => 37 [1] => 31 [2] => 29 [3] => 28 [4] => 20 [5] => 26 [6] => 34 [7] => 30 [8] => 25 )
如何获得该数组中的前5个索引,以及如何为这些剩余值编写查询
例如
[0]=>此的37
从图书表中获取id等于37的图书,类似于
请帮我做这个任何东西都会对有帮助
编辑
数组具有类似于此的值
Array ( [0] => 37 [1] => 31 [2] => 29 [3] => 28 [4] => 20 [5] => 26 [6] => 34 [7] => 30 [8] => 25 )
功能类似
if(!empty($books)) {
$values = array_count_values($books);
arsort($values);
$newArray = array_keys($values);
$views_books_array = array_slice($newArray, 0, 5);
$result = $this->db->where_in('book_id',$views_books_array)->get('books');
print_r($result);
return $result->result_array();
}
$result没有得到我需要的东西我做错了什么?
尝试array_slice()
函数:
// it will get 5 values from $books, starting from 0 offset (first position)
$values = array_count_values(array_slice($books, 0, 5));