I have the following URL: myexample.com/?city=Miami
and a large array (23k)
$e = $_GET["city"];
$myArray = array
(
array ("Miami","Florida"),
array ("Key West","Florida"),
array ("NOLA", "Luisiana"),
array ("Baton Rouge","Luisiana")
);
I'm looking for a solution to dynamically create a new array of cities that matches the state of the city in the URL, and echo all the cities from that state.
In other words:
if myexample.com/?city=NOLA, I would like to echo "Baton Rouge" and "NOLA" (from Luisiana)
if myexample.com/?city=Miami, echo "Key West" and "Miami" (from Florida)
etc.
There are quite a few similar questions answered already (here, here, but looping is not one of strengths (beginner).
Thank you.
EDIT1:
$resArray = array();
foreach($myArray as $arr) {
if(in_array($e, $arr))
$resArray[] = $arr;
}
print_r($resArray);
Result: Array ( [0] => Array ( [0] => Miami [1] => Florida ) )