Converting a php array to SQL array
I want something like the following:
$arrayOfValues = array(1,2,3,4);
$sqlArray = mysql_convertToSqlArray($arrayOfValues);
which then will return what in SQL would be:
(1,2,3,4)
but in php would be the string "(1开发者_JAVA技巧,2,3,4)"
There's no builtin function specifically for creating SQL arrays, but you could just join
the array and wrap it in parentheses:
$arrayOfValues = array(1,2,3,4);
$sqlArray = '(' . join(',', $arrayOfValues) . ')';
See this in action at http://www.ideone.com/KYApN.
Take a look at http://www.php.net/manual/en/function.implode.php.
This function can be used as following: $sqlArray = "(" . implode(",", $arrayOfValues) . ")";
[Edit]
Ps: join is an alias of implode.
精彩评论