Selecting data from MySql using a PHP array containing strings

Just a quick note on selecting mysql data using PHP arrays, specifically arrays containing strings.
MySql has the ability to accept array values via IN comparison operator.
See below:
SELECT * FROM table_name WHERE colum1 IN ($array)
Which could equate to something like:
SELECT * FROM table_name WHERE colum1 IN (2, 3, 8)
This will select all data from table_name where colum1 = all array values*
*Assuming these values are numerical and not strings.
If you want to select MySql data from an array that contains strings then one of the quickest and easiest possibilities is to implode your array into a single string to form a new variable that you can use in your MySql SELECT command in brackets after IN.
Like so:
$array_strings = implode("', '", $array();
SELECT * FROM table_name WHERE colum1 IN ('$array_strings')
Here we are using $array_strings to store all values inside of $array() separated with what ever is between ""
For instance:
$array[] = "ax";
$array[] = "au";
$array[] = "xb";
$array_strings = implode("|", $array();
echo $array_strings
Would display:
ax|au|xb
A good thing to know, but not exactly fitting for the syntax required while using IN.
We need to read IN (ax, au, xb).
So we added ' ' to either side of our variable $array_strings and place all of that in brackets:
$array[] = "ax";
$array[] = "au";
$array[] = "xb";
$array_strings = implode("' '", $array();
$sql="SELECT * FROM table_name WHERE colum1 IN ('$array_strings')";
Hopefully somebody will find this of some use
