Created
June 29, 2015 05:14
-
-
Save mithereal/6f5c98168688e6c7dbb2 to your computer and use it in GitHub Desktop.
arraytosql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function arrayToSql($array=array(),$pre='',$post='',$xor='&&') | |
{ | |
$end = end(array_keys($array)); | |
$sql = $pre; | |
foreach($array as $k =>$v){ | |
$sql .= "`$k` = '$v' "; | |
if($k != $end){ | |
$sql .= "$xor "; | |
} | |
} | |
$sql = $post | |
return $sql; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment