我创建了一个包含5列和'好处的表格。是列之一。我可以获得整个数据,但我需要从“好处”获得前6个字母。领域。福利栏目有300多个。 我的控制器代码
public function List(Request $request)
{
if($request->ajax()){
$data = Package::get();
$list = array();
$i=1;
foreach ($data as $key => $Package) {
$dd = array();
if($Package->free_benifits != ""){
array_push($dd, '<center>'.$Package->free_benifits.'</center>');
}else {
array_push($dd, '<center>-</center>');
}
}
答案 0 :(得分:0)
您可以使用substr函数剪切具有开始和长度的字符串
public function List(Request $request)
{
if($request->ajax()){
$data = Package::get();
$list = array();
$i=1;
foreach ($data as $key => $Package) {
$dd = array();
if($Package->free_benifits != ""){
$benifits=substr($Package->free_benifits,0,5);
array_push($dd, '<center>'.$benifits.'</center>');
}else {
array_push($dd, '<center>-</center>');
}
}