[英]Array - how to replace record with newly added
我得到了下面的數組,我想保留最近添加的記錄,即[2],並刪除其他記錄
Array (
[0] => Array ( [id] => 1 [is_sub] => 0 [product] => New [quantity] => 1 [price] => [total_item_price] => 0 [comments] => )
[1] => Array ( [id] => 1 [is_sub] => 0 [product] => Old [quantity] => 1 [price] => [total_item_price] => 0 [comments] => )
[2] => Array ( [id] => 4 [is_sub] => 0 [product] => Mix [quantity] => 1 [price] => [total_item_price] => 0 [comments] => ) )
我得到了一個答復,謝謝您的幫助。
$last = array_slice($orders, -1, 1, true);
更短:
$last = array_pop($orders);
$last_data = array_pop($data);
print_r($last_data);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.