Last active
March 16, 2020 12:07
-
-
Save antom/680600a3bb83267dea80 to your computer and use it in GitHub Desktop.
A quick method to quote the values of an array using implode/explode
This file contains 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 quote_array_values($array) { | |
return explode(',', sprintf( | |
'"%s"', | |
implode('","', $array) | |
)); | |
} | |
$params = array( | |
'one', | |
'two', | |
'three', | |
); | |
$output = array( | |
'original' => $params, | |
'quoted' => quote_array_values($params), | |
); | |
echo '<pre>', print_r($output, 1), '</pre>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment