0

What am I doing wrong? How do I get the number of the array so I can I assign the proper salesman for the city selected? In this example I would want to get 1, since Ambler is the city I'm looking for.

    $cities = array (
  0 => array("Aldenville", "Analomink"),
  1 => array("Abington", "Ambler", "Ardmore", "Avondale"),  
  2 => array("Ackermanville", "Albrightsville", "Allens Mills", "Alpha"),
  3 => array("Adamstown", "Alburtis", "Allentown"));   

if (($key = array_search("Ambler", $cities)) === false) {
    echo "Not found";
} else{
    echo $key;
}
Scotty Gdog
  • 141
  • 1
  • 2
  • 6

1 Answers1

0

You need to add a search level. You made a 2D-Array of cities, but you're searching in 1D. When you search for a specific city, you have search for every (sub)array in the array '$cities'

J.D.
  • 4,511
  • 2
  • 7
  • 20