2

私はこの配列を構築しました

 <?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>

$bhistory の最後の 10 行だけをエコーし​​たい。

私は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 が配列であると想定しています。

何が間違っているのかわからない、助けが必要

前もって感謝します。

4

2 に答える 2

0

答えはおそらく嘘ではないと思いますarray_slice

for ループを使用すると、配列の最後の 10 個の要素を非常に簡単に確認できます。

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'];
}
于 2015-03-29T15:01:19.260 に答える