Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Array ( [0] => LAMPION [1] => BANBU [2] => DT-T300-FNS [3] => T65 [4] => DT-299-FNS [5] => T30 )
我有一个看起来像这样的数组。问题是存储在数组中的数据不一致,因此我必须在数组中搜索此模式“xx-xxx-xxx”并将其存储在变量中。有什么办法可以做到吗?真的需要帮助
是的。
$matches = preg_grep('/^.{2}-.{3}-.{3}\z/', $array);
如果您想要第一个,只需添加[0](对于 < PHP 5.4,您首先需要一个临时变量)。
[0]