开发者

PHP Array Operation

开发者 https://www.devze.com 2022-12-17 03:48 出处:网络
$arr = array(\'id1\',\'id2\',...开发者_JAVA技巧); How to get #id1,#id2,.. from the above array?$arr = array(\'id1\', \'id2\', ...);
$arr = array('id1','id2',...开发者_JAVA技巧);

How to get #id1,#id2,.. from the above array?


$arr = array('id1', 'id2', ...);

$ids = '#' . join(',#', $arr);

echo $ids;  // => #id1,#id2,...


$arr[0];
$arr[1];

The code you just provided is the same as

$arr = array(
    0 => "id1",
    1 => "id2");

In order to make a list of ids in CSS

$string = '';
foreach($arr as $id)
{
    $string .= "#" . $id . " ";
}


you can iterate the array

foreach ($arr as $k){
  print "#".$k."\n";
}

each "$k" is your array items

0

精彩评论

暂无评论...
验证码 换一张
取 消