Skip to content

Instantly share code, notes, and snippets.

@namnv609
Created February 19, 2016 08:54
Show Gist options
  • Save namnv609/0f7e06d69e0e14ace9ec to your computer and use it in GitHub Desktop.
Save namnv609/0f7e06d69e0e14ace9ec to your computer and use it in GitHub Desktop.
Vietnam mobile phone classify
<?php
$phones = [
"0987654321",
"0912345678",
"01234567890",
"01650930293",
"0992938392",
"01882938493",
"0902938292",
"01999382738",
"01202938493",
"0929483920",
"0999292399",
"0939382738",
"0943829304",
"01279493828",
];
$operatorRegEx = [
'Viettel' => '(09[6-8]|016[2-9])',
'Vinaphone' => '(09(1|4)|012([2-5]|7|9))',
'Mobifone' => '(09(0|3)|012([0-2]|6|8))',
'Vietnam Mobile' => '(092|018(6|8))',
'Gmobile' => '(0(9|1)9{1,2})',
];
foreach ($operatorRegEx as $operator => $regEx) {
$phoneList[$operator] = preg_grep('/^' . $regEx . '[0-9]+$/', $phones);
}
echo "<pre>";
var_dump($phoneList);
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment