首页 > 解决方案 > 有没有办法对数组进行子串化?

问题描述

我想对查询给出的数组进行子串化

CONTROLLER(EX. 值(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)}}

错误

substr() expects parameter 1 to be string, object given

标签: phparrayslaravelsubstr

解决方案


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

$store=array();

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

foreach($tables as $table){
    $store[] = substr($table->Tables_in_database,-4);
}

推荐阅读