我有一個數組,如下圖所示。正如你所看到的,陣列總共有20個尺寸。我如何將它裁減到只有3個尺寸?拉拉維爾有沒有雄辯的方式來做到這一點?Laravel,是否可以刪除部分數組大小?
穆罕默德Inaam穆尼爾回答
$null_index = 0;
$current_index = 0;
foreach ($rows as $key => $value)
{
$is_null = true;
foreach($value as $value_item)
{
if($value_item != null)
$is_null = false;
break;
}
if($is_null)
{
$null_index = $current_index;
break; // break the loop
}
$current_index++;
}
$rows = $rows->slice(0, $null_index);
dd($rows);
您可以用' - >取()'或' - >限制()'得到的只是一些記錄:) –
怎麼樣刪除其餘的? – begineeeerrrr
沒有必要刪除它會給過濾結果,只是從數據庫中取幾條記錄 –