PHP splitting array into two arrays based on value

前端 未结 5 1062
小蘑菇
小蘑菇 2021-02-19 06:43

I have a PHP array that I am trying to split into 2 different arrays. I am trying to pull out any values that contain the word \"hidden\". So one array would contain all the v

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 07:21

    Maybe it's just me, but I would go for the clarity of regular expressions...

    foreach($myArray as $item) {
        if (preg_match("/hidden$/i", $item)) {
            array_push($arr2, $item);
        } else {
            array_push($arr1, $item);
        }
    }
    

提交回复
热议问题