Эхо только последние 10 значений массива

у меня есть этот массив сборки

 <?php
$bidding_history = $current_bidding_data;
if(is_array($bidding_history) && !empty($bidding_history) ){
?>

<ul class="list-group">
<?php
foreach($bidding_history as $kk => $bhistory){
?>

с $ bhistory повторяется следующим образом,

<li class="list-group-item"><span class="badge pull-right"><small><?php echo $bhistory['username'] ?></small></span>

я хочу повторить только последние 10 строк $ bhistory.

я пытался в array_splice

<li class="list-group-item"><span class="badge pull-right"><small><?php echo array_splice ($bidding_history['username'], -1, 10, true) ?></small></span>

но на переднем конце я получаю код ошибки:
Предупреждение: array_slice () ожидает, что параметр 1 будет массивом, задан ноль

я не знаю что делаю не так, нужна помощь

Заранее спасибо.

2

Решение

Ты можешь использовать array_slice(); за это.

Вот пример:

<?php
$bidding_history_new = array_slice($bidding_history, -10);
foreach($bidding_history_new as $kk => $bhistory){
//whatever you do here

}
?>

Подробнее о PHP array_slice(); функция: http://php.net/manual/en/function.array-slice.php

2

Другие решения

Я думаю, что ответ может быть не в array_slice,

Вы можете легко просмотреть последние 10 элементов массива с помощью цикла for:

for($i = count($bidding_history) - 10; $i < count($bidding_history); $i++) {
?>
<li class="list-group-item"><span class="badge pull-right"><small>
<?php
echo $bidding_history[$i]['username']
?>
</small></span>
<?php
}

Или же

for($i = count($bidding_history) - 10; $i < count($bidding_history); $i++) {
//...whatever you want to do...
$username = $bidding_history[$i]['username'];
}
0