在PHP中,如何从数组中删除子字符串?

时间:2013-09-10 23:58:47

标签: php cakephp-2.0

我在数组下面。我想从数组中删除gupta并希望返回剩余的数组。

$array = array('dave gupta', 'stephen gupta', 'rajni goel');
$substring want to delete gupta

输出required =>

$array = array('dave', 'stephen', 'rajni');

提前感谢您的帮助。

在我的实际代码中

$this->Html->link($serv[$index]['Service'] => by this I can getting all the value from the data base.

我的价值观

Web Development
Graphic design
App Development
Digital design

我想只删除开发并希望fetech其余的数组?

echo  urldecode(strtoupper($this->Html->link($serv[$index]['Service']['name'],array('controller' => $serv[$index]['Service']['controller'],
                   'action' => $serv[$index]['Service']['action'],$serv[$index]['Service']['id'],
                   'admin' => false,
                   'plugin' => false),array('class'=>'menuForFooter2'))));

1 个答案:

答案 0 :(得分:-1)

array_filter适合这种情况。

$array = array('dave', 'gupta','stephen', 'gupta','rajni', 'goel');
$output=array_filter($array, function($s){return $s!='gupta';});