array_search for string with space
<p>I have correctly created an array and have an array item with:</p>

<pre><code>$array[2] = "Automotive Repairs and Servicing";
</code></pre>

<p>I try to do a search on $array for Automotive Repairs and Servicing and it returns false:</p>

<pre><code>array_search('Automotive Repairs and Servicing', $array);
</code></pre>

<p>I found that it returns false because I have a space within the search string, i.e. Automotive(space)Repairs(space)and(space)Servicing.</p>

<p>Does anyone know how I can make my search successfully return the key?
I have tried with space as %20, \n, and &nbsp; as follows:</p>

<pre><code>array_search('Automotive%20Repairs%20and%20Servicing', $array);
array_search('Automotive\nRepairs\nand\nServicing', $array);
array_search('Automotive&amp;nbsp;Repairs&amp;nbsp;and&amp;nbsp;Servicing', $array);
</code></pre>

<p>I will continue to try and fix this problem and if I solve it I will post my answer.</p>

<p>...Thank you for your answer below. I tried your code and it worked for me too.</p>

<p>My real array is actually constructed of data from a database using mysql query and putting the result straight into the array. So not quite sure where the problem lies now.</p>

<p>...</p>

<p><strong>My Answer:</strong></p>

<p>Thank you all for responding and helping me with this problem.</p>

<p>I have found my problem... and I'm extremely <strong>embarrassed</strong>.</p>

<p>Turns out there was a space that I didn't see at the end of the string 'Automotive Repairs and Servicing ' in my database.
I've struck this before, my mysql database just like to mess with my head like this sometimes. </p>

<p>So for anyone else out there that gets their mysql result and sticks it into an array then strikes similar problems to this, make sure that your mysql isn't 'pranking' you with a space (invisible to the human eye) in your data.</p>

<p>I'm going out for a cigarette.</p>
