标签: php arrays
如果我有这样的数组
$var =array('apple','egg','banana','carrot','egg','cat','dog','egg','eggplant','fish','banana');
我希望只打印所有值“egg”
egg,egg,egg
答案 0 :(得分:0)
也许是矫枉过正,但我很无聊:
$word = 'egg'; $result = implode(',', preg_grep("/^$word$/", $var));