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
1 2 3 4 5 6 7 8 9 10 11 | $wheresql = implode(' AND ', $wherearr );
function simplode( $ids ) {
return "'" .implode( "','" , $ids ). "'" ;
}
$itemidarr = array ();
if ( empty ( $_POST ['item'])) {
showmessage('space_no_item');
}
$itemidstr = simplode( $_POST ['item']);
|
Copy after login
Instance code:
1 2 3 4 5 | $catidarr = array ();
if (! empty ( $t1 )) $catidarr [] = '\''. $t1 .'\'';
if (! empty ( $t2 )) $catidarr [] = '\''. $t2 .'\'';
if (! empty ( $t3 )) $catidarr [] = '\''. $t3 .'\'';
$catidstr = implode(' , ', $catidarr );
|
Copy after login
SQL statement example:
1 | SELECT uid, name, namestatus FROM ".tname('space')." WHERE uid IN ( ".simplode($uids)." )
|
Copy after login
Example, batch Delete data
SQL: $SQL="delete from `doing` where id in ('1,2,3,4')";
Data is separated by commas.
Form: