PHP 提取数组中的特定的值

需求:

前端展示:

(1)之前的页面:

(2)修改后的页面:

之前接口返回的数据 :

解决办法:提取tags 中的 '约' 的数组 添加到一个新的数组中去

1:一开始想到的是 使用strops 的函数 返回 存在的位置 ,但是 字符串知道了位置 不是很方便 获取到相应的值。(试了很久 结果不是很理想)

2:使用正则表达式 (处理这种需要 直接正则 ,不要考虑strops,array_search ,或者其他的 的函数了):

复制代码
        foreach ($item['good'] as &$index) {
                        $pattern = '/约.*/';
                        preg_match_all($pattern, implode(', ',$index['tags']), $matches);
                        $index['tag'] =  explode(',', implode(",", $matches[0]));
                    }
相关推荐
QX_hao1 小时前
【Go】--反射(reflect)的使用
开发语言·后端·golang
inferno1 小时前
Maven基础(二)
java·开发语言·maven
我是李武涯2 小时前
从`std::mutex`到`std::lock_guard`与`std::unique_lock`的演进之路
开发语言·c++
史不了3 小时前
静态交叉编译rust程序
开发语言·后端·rust
读研的武3 小时前
DashGo零基础入门 纯Python的管理系统搭建
开发语言·python
Andy3 小时前
Python基础语法4
开发语言·python
但要及时清醒3 小时前
ArrayList和LinkedList
java·开发语言
孚亭4 小时前
Swift添加字体到项目中
开发语言·ios·swift
hweiyu004 小时前
Go、DevOps运维开发实战(视频教程)
开发语言·golang·运维开发