在Laravel Framework中分割字串 [英] Split string in Laravel Framework

查看:74
本文介绍了在Laravel Framework中分割字串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Laravel Framework中拆分字符串并将其显示在表中?我从数据库中获取数据,该数据由一列组成,但以字符串形式,例如 {1234,normal,r4r3r2} .我想用逗号将其分为三个不同的部分/值,并在三列的表格中显示.

How do I split string and display it in a table in Laravel Framework? I fetch data from my database that consists of one column but in a string such as { 1234, normal, r4r3r2 }. I want to split it into three different parts/values by commas and display it in a table of three columns.

目前,我只能显示数据而不会拆分它们.

For now, I only can display the data without splitting the them.

我的HomeController:

My HomeController:

public function index()
  {
    $test = Test::all();
    return view('home')->with('test', $test);
  }

我的home.blade.php:

My home.blade.php:

<ol>
   @foreach($test as $row)
     <li>{{ $row->data }}</li>
   @endforeach
</ol>

推荐答案

首先爆炸$ test变量以获得Array,

First explode the $test variable to get Array,

<ol>
 @foreach(explode(',',$test) as $row)
  <li>{{ $row }}</li>
 @endforeach
</ol>

使用foreach单键爆炸后,我们可以从数组进行访问.希望对您有帮助.

After explode using foreach single key we can access from the array. I hope it helps.

这篇关于在Laravel Framework中分割字串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆