如果项目值包含搜索的字符串字符,则从数组中删除项目 [英] Remove item from array if item value contains searched string character

查看:16
本文介绍了如果项目值包含搜索的字符串字符,则从数组中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从网页 URL 构建的数组.

I have an array built from the URL of a webpage.

如果该数组中的一项包含 ?符号(问号符号)然后我想从数组中删除该项目.

If an item in that array contains the ? symbol (The question mark symbol) then I want to remove that item from the array.

$array = 'news','artical','?mailchimp=1';

我怎么能这样做?我见过很多例子,其中搜索到的字符串是整个值,而不是它只是单个字符或值的一部分.

How could I do this? I've seen many examples where the searched string is the whole value, but not where its just a single character or just part of the value.

谢谢

推荐答案

http://www.php.net/manual/en/function.array-filter.php

function myFilter($string) {
  return strpos($string, '?') === false;
}

$newArray = array_filter($array, 'myFilter');

这篇关于如果项目值包含搜索的字符串字符,则从数组中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆