title: PHP in_array match search value to array list
body: <p>I have a search function on my page, where user can able to search US states to find property. However, in my database record, abbreviation only was set on each state name. So I download a copy of US states in array list format.</p>
  
  <p><strong>Code Fig. 1</strong></p>
  
  <pre><code>$searchStates = array(
      'Alabama'          =&gt;'AL',
      'Alaska'           =&gt;'AK',
      'Arizona'          =&gt;'AZ',
      'Arkansas'         =&gt;'AR',
      'California'       =&gt;'CA',
      'Colorado'         =&gt;'CO',
      'Connecticut'      =&gt;'CT',
      'Delaware'         =&gt;'DE',
      'Florida'          =&gt;'FL',
      'Georgia'          =&gt;'GA',
      'Hawaii'           =&gt;'HI',
      'Idaho'            =&gt;'ID',
      'Illinois'         =&gt;'IL',
      'Indiana'          =&gt;'IN',
      'Iowa'             =&gt;'IA',
      'Kansas'           =&gt;'KS',
      'Kentucky'         =&gt;'KY',
      'Louisiana'        =&gt;'LA',
      'Maine'            =&gt;'ME',
      'Maryland'         =&gt;'MD',
      'Massachusetts'    =&gt;'MA',
      'Michigan'         =&gt;'MI',
      'Minnesota'        =&gt;'MN',
      'Mississippi'      =&gt;'MS',
      'Missouri'         =&gt;'MO',
      'Montana'          =&gt;'MT',
      'Nebraska'         =&gt;'NE',
      'Nevada'           =&gt;'NV',
      'New Hampshire'    =&gt;'NH',
      'New Jersey'       =&gt;'NJ',
      'New Mexico'       =&gt;'NM',
      'New York'         =&gt;'NY',
      'North Carolina'   =&gt;'NC',
      'North Dakota'     =&gt;'ND',
      'Ohio'             =&gt;'OH',
      'Oklahoma'         =&gt;'OK',
      'Oregon'           =&gt;'OR',
      'Pennsylvania'     =&gt;'PA',
      'Rhode Island'     =&gt;'RI',
      'South Carolina'   =&gt;'SC',
      'South Dakota'     =&gt;'SD',
      'Tennessee'        =&gt;'TN',
      'Texas'            =&gt;'TX',
      'Utah'             =&gt;'UT',
      'Vermont'          =&gt;'VT',
      'Virginia'         =&gt;'VA',
      'Washington'       =&gt;'WA',
      'West Virginia'    =&gt;'WV',
      'Wisconsin'        =&gt;'WI',
      'Wyoming'          =&gt;'WY'
  );
  </code></pre>
  
  <p><strong>Case:</strong></p>
  
  <p>My clients use to search state name, <code>ex: Tennessee</code> but in my result, it will display <strong>No Record</strong> due of abbreviation only was saved in my database. I would like to use this array list of <code>$searchStates</code> to match my abbreviation list of states. I tried to use <code>in_array</code> function, but it seems not working correctly. See my actual code.</p>
  
  <p><strong>Code Fig. 2</strong></p>
  
  <pre><code>if (in_array( $search, $searchStates )) {
  
      $property-&gt;where(function($query) use ($search) {
          $query-&gt;where('property.state','like','%'.$search.'%')
              -&gt;orWhere('property.contact_name','like','%'.$search.'%')
              -&gt;orWhere('property.address','like','%'.$search.'%')
              -&gt;orWhere('property.city','like','%'.$search.'%')
              -&gt;orWhere('property.name','like','%'.$search.'%');
      });
  
  }
  </code></pre>
  
  <p><strong>Goal</strong></p>
  
  <p>I would like to use the <code>$searchStates</code> list to match my database record (which is in abbreviation format of the US states) and display the correct output in my search result page.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Was this <code>in_array</code> function would work or should I use another function? I will appreciate your help.</p>