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」を検索して変数に格納する必要があることです。私がそれをすることができる方法はありますか?本当にhlpが必要
はい。
$matches = preg_grep('/^.{2}-.{3}-.{3}\z/', $array);
最初のものが必要な場合は、追加するだけ[0]です(<PHP 5.4の場合は最初に一時変数が必要です)。
[0]