note 59508 deleted from function.implode by felipe
| From: | felipe@php.net | Date: | Mon, 24 Dec 2007 02:14:12 +0000 |
| Subject: | note 59508 deleted from function.implode by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133941@lists.php.net to get a copy of this message | ||
Note Submitter: Hotmail resident Tree2054
----
Combining into one function:
function implode_with_options($assoc_array, $prefix = '', $k_v_glue = '', $vwrap
= '', $seperator = '')
{
foreach ($assoc_array as $k => $v)
{
$tmp[] = $k . $k_v_glue . $vwrap . $v . $vwrap;
}
return $prefix . implode($seperator, $tmp);
}
$items = array('Apples', 'number' => 3, 'Vehicle' =>
'');
// For a query string:
echo implode_with_options($items, '?', '=', '', '&');
/**
* Produces
* ?0=Apples&number=3&Vehicle=
*/
// For a SQL query
echo implode_with_options($items, '', '=', '"', ', ');
/**
* Produces
* 0="Apples", number="3", Vehicle=""
*/