基于特殊字符爆炸

I have an issue where, I am not able to explode based on database values.

my database values can be as such

  1. 1-10
  2. < 10
  3. ">20

I want to explode based on specail characters and put them in an array.

for example

$array = explode("/ (-) "/, Model::find()->findByPj($model->id)); 

How do I get the regex for that to explode dynamically based on the data

explode() can't handle regular expressions. You are looking for preg_split() and the correct pattern is (-|<|>). The pattern basically means: match - or < or >. So the code should look like this:

$array = preg_split("/ (-|<|>) /", Model::find()->findByPj($model->id));

You can use preg_split(regex_pattern, string) like this:

$array = preg_split("(-)", 'some string here, lorem-ipsum'); 
var_dump($array);

Hope this helps!