As you have a situation where one suburb can have more than one postcode you need to store the data as an array within an array, using the suburb as the key to the outer array.
Like so:-
<?php
$postcodes = file('postcodes.txt');
foreach ($postcodes as $line) {
list($po, $burb) = explode(",", $line);
$burb = str_replace(PHP_EOL, '', $burb);
$pcodes[$burb][] = $po;
}
print_r($pcodes);
$userInput = 'MELBOURNE';
if ( array_key_exists($userInput, $pcodes) ) {
foreach ( $pcodes[$userInput] as $oneOfTheCodes ) {
echo 'The postcode for ' . $userInput . ' is ' . $oneOfTheCodes . PHP_EOL;
}
} else {
echo 'Suburb does not exist';
}
The output from this would be
Array
(
[MELBOURNE] => Array
(
[0] => 3000
[1] => 3001
[2] => 3004
[3] => 8001
)
[EAST MELBOURNE] => Array
(
[0] => 3002
)
[WEST MELBOURNE] => Array
(
[0] => 3003
)
)
The postcode for MELBOURNE is 3000
The postcode for MELBOURNE is 3001
The postcode for MELBOURNE is 3004
The postcode for MELBOURNE is 8001