我有一个数组,如下图所示。正如你所看到的,阵列总共有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
没有必要删除它会给过滤结果,只是从数据库中取几条记录 –