I can't think any way to merge the first two arrays, there is no data that can tell where an instrument is. Also, more than a store can have an instrument, so I came up with an example. Array $a
is where you save instrument names as keys and store_id as values. Array $b
is the store array.
<?php
$a = array(
'viola' => array('1','2','12','13'),
'guitar' => array('2','3','8'),
'trumpet' => array('5'),
'banjo' => array('6','10'),
'flute' => array('4'),
'oboe' => array('5','11'),
'ukulele' => array('23'),
'tuba' => array('1','5'),
'cello' => array('7')
);
$var = 'guitar'; # $_POST or $_GET
$result = $a[$var]; # retrieve stores id
$stores = array(
'1' => array('name' => 'Rock Store 1','address' => 'another street n1'),
'2' => array('name' => 'Rock Wave','address' => 'that plaza n2'),
'3' => array('name' => 'Jazz Store 2','address' => 'avenue n1115'),
'4' => array('name' => 'Bohemian Rhapsody Store','address' => 'plaza n2'),
'5' => array('name' => 'Indie Music Instruments','address' => '3rd street n123'),
'6' => array('name' => 'Whatever Music Co.','address' => 'avenue n222'),
'7' => array('name' => 'Blues Brothers','address' => '1060 West Addison')
);
echo $var . "\n\n";
# display store names and addresses
foreach($result as $key => $value)
{
echo $stores[$value]['name'] . "\n";
echo $stores[$value]['address'] . "\n\n";
}
?>
The above will output:
guitar
Rock Store 1
another street n1
Indie Music Instruments
3rd street n123
Blues Brothers
1060 West Addison
Hopefully someone else will help you to find a better solution.
I'm almost sure array_keys()
can be used to make something …