Insert just the array key without value
I have the following code in PHP:
$keys = array('a', 'b', 'c');
$data = array();
$data[0] = array_fil开发者_如何学Pythonl_keys($keys,'');
After some follow-up code, when the array set is empty, it returns:
a,b,c
,,,
I've slimmed down to the problem is $data[0] = array_fill_keys($keys,'');
What can I do to have the result as:
a,b,c
Thanks.
$keys = array('a', 'b', 'c');
$data = array();
echo $data[0] = $keys[0];
echo $data[1] = $keys[1];
echo $data[2] = $keys[2];
or
$keys = array('a', 'b', 'c');
$data = array();
foreach ($keys as $value) {
echo $value . ',';
}
it will output the letter a and a,b,c,
rtrim()
function remove chars from right side of the strig, for left side use ltrim()
精彩评论