亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 PHP 數組中獲取值并顯示它們

從 PHP 數組中獲取值并顯示它們

PHP
瀟瀟雨雨 2022-08-05 16:00:57
我正在做一個名為FUND的crud,在那里我可以使用PHP內爆方法存儲很多東西以及數組。在那個數組中,我存儲了一些基金Id。下面是數組創建代碼:<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以下是商店代碼:public function store(Request $request){    $request->validate([        'title'=>'required',        'image'=>'required',        'description',        'available'=>'required',        'buy'=>'required',        'account',        'receive',    ]);    $image = $request->file('image');    $new_name = rand() . '.' . $image->getClientOriginalExtension();    $image->move(public_path('funds'), $new_name);    $form_data = array(        'title'=>$request->title,        'image'=>$new_name,        'description'=>$request->description,        'available'=>$request->available,        'buy'=>$request->buy,        'buyrate'=>$request->buyrate,        'sellrate'=>$request->sellrate,        'account'=>$request->account,        'receive'=>implode(',', (array)($request->receive)),    );    Fund::create($form_data);    return redirect('/admin/fund');}我使用PHP分解方法在我的索引頁上顯示該數組。$receive=[];foreach($funds as $fund){    $receive = explode(",",$fund->receive);}正如我所提到的,我正在將基金ID存儲在該數組中。因此,我想使用基金 ID 顯示整行。為此,我使用以下查詢:但標題圖像顯示如下我怎樣才能在沒有任何括號的情況下獲得標題,圖像和其他員工?
查看完整描述

2 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

經過幾次研究,我修復了它。答案如下:


@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


查看完整回答
反對 回復 2022-08-05
?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

而不是括號嘗試使用標簽,就像我在下一個示例中所做的那樣;

<img src="<?=$fund=\App\Fund::where(['id'=>$r])->get('image')?>"...

如果到圖像的路由是好的,它應該有效。如果您在此之后遇到任何其他問題,請告訴我:)


查看完整回答
反對 回復 2022-08-05
  • 2 回答
  • 0 關注
  • 167 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號