有没有一种方法可以对数组进行子字符串化?

问题描述 投票:0回答:4

我想对查询给定的数组进行子字符串化

CONTROLLER(例如,值(Year_Report_2019,Year_Report_2020)

 $store=array();

 $tables = \DB::select("SHOW TABLES WHERE Tables_in_database LIKE '%Year_Report_%'");

    foreach($tables as $this){

     $get= substr($this,-4);

     $store[] = $get;
   }

BLADE想要显示(2019,2020)的结果

{{implode(",", $store)}}

ERROR

substr() expects parameter 1 to be string, object given
arrays laravel substr
4个回答
1
投票

您解析结果错误。 (避免使用变量名$this


2
投票

是,implode功能将为您完成:


1
投票
$array = ['Year_Report_2019','Year_Report_2020'];


array_walk($array, function(&$item) { 
    return $item = preg_replace("/\D/", '', $item);
});

1
投票

这里无需使用foreach,只需用您的愿望表达将这个数组内陷

© www.soinside.com 2019 - 2024. All rights reserved.