In phpimplode() function combines the array elements into a string, which is exactly the same as the explode function. Let’s take a look at a few implode function example.
Syntax
implode(separator,array) //array is an array and separator is a separator.
Example
//链接搜索条件 $wheresql = implode(' AND ', $wherearr); //链接搜索条件 function simplode($ids) { return "'".implode("','", $ids)."'"; } $itemidarr = array(); //初始化itemidarr数组 if(empty($_POST['item'])) { //判断提交过来的是否存在待操作的记录,如果没有,则显示提示信息并退出 showmessage('space_no_item'); } $itemidstr = simplode($_POST['item']); //用逗号链接所有的操作ID //对提交的数据进行检查
Instance code:
$catidarr = array(); if(!empty($t1)) $catidarr[] = '\''.$t1.'\''; if(!empty($t2)) $catidarr[] = '\''.$t2.'\''; if(!empty($t3)) $catidarr[] = '\''.$t3.'\''; $catidstr = implode(' , ', $catidarr); //用逗号链接所有的操作ID
SQL statement example:
SELECT uid, name, namestatus FROM ".tname('space')." WHERE uid IN (".simplode($uids).")
Example, batch Delete data
SQL: $SQL="delete from `doing` where id in ('1,2,3,4')";
Data is separated by commas.
Form: