Assuming that countryids are unique and always numeric, and country names are always lower-case alphabetic:
<?php
$data = array();
$data[0][0] = '1';
$data[0][1] = 'india';
$data[1][1] = 'germany';
$data[1][0] = '2';
$data[2][1] = 'america';
$data[2][0] = '3';
$array = array();
foreach ($data as $pair) {
if (ctype_digit($pair[0])) {
$array[$pair[0]] = $pair[1];
} else {
$array[$pair[1]] = $pair[0];
}
}
asort($array);
foreach ($array as $key => $value) {
echo $key . ' ' . $value . '<br>';
}
?>
My idea here is to use the countryid as the key of an associative array of country names.
We then sort this array using asort(), which maintains the key-value correspondence.