从PHP数组中获取值并显示它们
我正在做一个名为FUND的crud,在这里我可以使用PHP内爆方法存储很多东西和一个数组。在那个数组中,我存储了一些基金Id。 以下是数组创建代码:从PHP数组中获取值并显示它们,php,laravel-5.8,Php,Laravel 5.8,我正在做一个名为FUND的crud,在这里我可以使用PHP内爆方法存储很多东西和一个数组。在那个数组中,我存储了一些基金Id。 以下是数组创建代码: <div class="custom-checkbox"> <label for="receive[]">Select Receive Funds</label> @foreach($funds as $fund) <div class="custom-control custom-c
<div class="custom-checkbox">
<label for="receive[]">Select Receive Funds</label>
@foreach($funds as $fund)
<div class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" name="receive[]" id="{{$fund->id}}" value="{{$fund->id}}">
<label for="{{$fund->id}}" class="custom-control-label">{{$fund->title}}</label>
</div>
@endforeach
我使用PHP explode方法在索引页上显示该数组
正如我提到的,我将基金id存储在该数组中。因此,我想通过使用基金ID显示整行。为此,我使用以下查询:
@foreach($receive as $r)
<a href="/multi" class="list-group-item">
<p>
<img src="{{$fund=\App\Fund::where(['id'=>$r])->get('image')}}" width="32px" height="32px"> {{$fund=\App\Fund::where(['id'=>$r])->get('title')}}
<span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
<small>Reserve: {{$fund=\App\Fund::where(['id'=>$r])->get('available')}}<br>Exchange rate: {{$fund=\App\Fund::where(['id'=>$r])->get('buyrate')}}</small>
</span>
</p>
</a>
@foreach($r作为$r接收)
@endforeach
但是标题图像是这样显示的
我怎样才能在没有括号的情况下获得标题、图像和其他员工?尝试使用标签,而不是括号,就像我在下一个示例中所做的那样
<img src="<?=$fund=\App\Fund::where(['id'=>$r])->get('image')?>"...
$r])->get('image')?>“。。。
如果到图像的路径是好的,它应该可以工作。
如果在此之后您还有任何其他问题,请告诉我:)经过几次研究,我解决了它。以下是答案:
@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp
@foreach($receives as $r)
<a href="/multi" class="list-group-item">
<p>
<img src="{{ $r->image_url }}" width="32px" height="32px"> {{ $r->title }}
<span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
<small>Reserve: {{ $r->available }}<br>Exchange rate: {{ $r->buyrate }}</small>
</span>
</p>
</a>
@endforeach
@php$receive=\App\Fund::其中('id',$receive)->get();@endphp
@foreach($r作为$r接收)
@endforeach
<img src="<?=$fund=\App\Fund::where(['id'=>$r])->get('image')?>"...
@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp
@foreach($receives as $r)
<a href="/multi" class="list-group-item">
<p>
<img src="{{ $r->image_url }}" width="32px" height="32px"> {{ $r->title }}
<span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
<small>Reserve: {{ $r->available }}<br>Exchange rate: {{ $r->buyrate }}</small>
</span>
</p>
</a>
@endforeach