需求:
前端展示:
(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]));}