explode
Mysql where id is in array [duplicate]
$string=”1,2,3,4,5″; $array=array_map(‘intval’, explode(‘,’, $string)); $array = implode(“‘,'”,$array); $query=mysqli_query($conn, “SELECT name FROM users WHERE id IN (‘”.$array.”‘)”); NB: the syntax is: SELECT * FROM table WHERE column IN(‘value1′,’value2′,’value3’)
Alternative of php’s explode/implode-functions in c#
String.Split() will explode, and String.Join() will implode.
php explode all characters [duplicate]
As indicated by your error, explode requires a delimiter to split the string. Use str_split instead: $arr = str_split(‘testing’); Output Array ( [0] => t [1] => e [2] => s [3] => t [4] => i [5] => n [6] => g )
PHP explode the string, but treat words in quotes as a single word
This would have been much easier with str_getcsv(). $test=”Lorem ipsum “dolor sit amet” consectetur “adipiscing elit” dolor”; var_dump(str_getcsv($test, ‘ ‘)); Gives you array(6) { [0]=> string(5) “Lorem” [1]=> string(5) “ipsum” [2]=> string(14) “dolor sit amet” [3]=> string(11) “consectetur” [4]=> string(15) “adipiscing elit” [5]=> string(5) “dolor” }
PHP: Split string into array, like explode with no delimiter
$array = str_split(“0123456789bcdfghjkmnpqrstvwxyz”); str_split takes an optional 2nd param, the chunk length (default 1), so you can do things like: $array = str_split(“aabbccdd”, 2); // $array[0] = aa // $array[1] = bb // $array[2] = cc etc … You can also get at parts of your string by treating it as an array: $string = … Read more
Add a prefix to each item of a PHP array
An elegant way to prefix array values (PHP 5.3+): $prefixed_array = preg_filter(‘/^/’, ‘prefix_’, $array); Additionally, this is more than three times faster than a foreach.