Php在Yii2项目中爆炸


Php explode in Yii2 project

在我的Yii2项目中,我有来自数据库列的数据。在数据库列中,数据如下。

12
13SeeP
2/3 
Seep2

这里我想让数组中的数字爆炸

  • [12]为第一行
  • [13]为第二行
  • [2,3]为第三行
  • [2]为第四行。

我不能使用爆炸来实现这个。我使用了trim

  public function classLabelImdg() {
        $imdgLabels = $this->transportImdg->imdg_sub_risk;
        $imdgLabelsTrim =  trim(preg_replace("/[^0-9,.'/]/","",$imdgLabels)); 
        $cleanImdgLabels = explode('/',$imdgLabelsTrim);
        $classLabelNo = TransportClass::find()->where(['class_no'=> $cleanImdgLabels])->all();
        return $classLabelNo;   
    }

上面正在做我想做的事情,但现在它正在重新安排我在数组中的数据。我希望它们以相同的顺序显示

我如何实现我的结果有任何帮助吗??

谢谢

像这样试试。这将用!替换非数字字符,然后在!字符上爆炸并删除所有空值。

$labels = [
    '12',
    '13SeeP',
    '2/3',
    'Seep2',
];
$results = [];
foreach ($labels as $v) {
    $results[] = array_filter(explode('!', preg_replace("/'D+/", '!', $v)));
}
print_r($results);

我的工作代码是

$aggregateResult[$index]['lab_number'] = explode('-',  $aggregateResult[$index] 
 ['lab_number'])[1];