【发布时间】:2018-03-07 19:02:55
【问题描述】:
我需要按日期对多维数组进行排序。 数据在名为价格的列中序列化,其中包含很少的值:价格和日期。 我在控制器中对它进行了反序列化,并且得到了 $hlisting->prices。 我认为这个价格是一个数组,我将按价格内的数据值对所有 $hlisting 进行排序。 (种类 $hlisting->prices->date)。
这是一个可能有用的代码。
<div class="price-dates">
@if(!empty($hlisting->prices))
@foreach($hlisting->prices as $prices)
<div class="price-date">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Period</label>
{!! Form::text('prices_dates[]', $prices['date'], array('class' => 'date-range form-control')) !!}
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Value</label>
{!! Form::text('prices_values[]', $prices['value'], array('class' => 'numeric form-control')) !!}
</div>
</div><!--col-->
<div class="col-sm-1">
<div class="form-group">
<label>Del</label>
<button type="button" class="del-price-date btn btn-sm btn-danger">
<i class="fa fa-trash"></i>
</button>
</div>
</div>
</div><!--row-->
</div>
@endforeach
@else
<div class="price-date">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Period</label>
{!! Form::text('prices_dates[]', NULL, array('class' => 'date-range form-control')) !!}
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Value</label>
{!! Form::text('prices_values[]', NULL, array('class' => 'numeric form-control')) !!}
</div>
</div><!--col-->
</div><!--row-->
</div>
@endif
</div>
我认为我应该在将 $hlisting 发送到视图的控制器中对其进行排序。
谢谢
【问题讨论】:
-
编辑:我不需要对 $hlisting 进行排序,而只需对 $hlisting->prices(包含值和日期)进行排序
-
对不起,这是一个对象而不是数组
标签: php arrays laravel sorting multidimensional-array