Something like this will work:
// get your list of numbers from DB
$phones = array( '971527139011', '171527139011' );
// get your list of country codes
$ccodes = array(
'1' => 'us',
'2' => 'uk',
'3' => 'de',
'44' => 'fi',
'123' => 'no',
'971' =>'uae',
'91' =>'india',
'92' =>'pakistan'
);
krsort( $ccodes );
foreach( $phones as $pn )
{
foreach( $ccodes as $key=>$value )
{
if ( substr( $pn, 0, strlen( $key ) ) == $key )
{
// match
$country[$pn] = $value;
break;
}
}
}
print_r( $country );
Edit
The data is pretty messy, I suggest you store it in different columns, but, if the structure of the data is always the same, this will extract the country/code from it:
$data = array( 'country : Denmark prefix:45', 'country : Pakistan prefix:92' );
foreach ( $data as $string )
{
$_a = explode( ':', $string );
$_b = explode( ' ', $_a[1] );
$ccode[$_a[2]] = $_b[1];
}
print_r( $ccode );