求段代码:判断数组里是不是有重复内容,如果有就只更新指定数量,没有就添加

WBOY
Release: 2016-06-13 12:01:40
Original
883 people have browsed it

求段代码:判断数组里是否有重复内容,如果有就只更新指定数量,没有就添加
内容:

一年级 X 2, 二年级 X 10 ,三年级 X 5 ……

判断里面是否有二年级,如果有就加5 结果:一年级 X 2, 二年级 X 15 ,三年级 X 5 ……
------解决方案--------------------

$qq = "一年级 X 2, 二年级 X 10 ,三年级 X 5 ";<br />$k = '二年级';<br />echo preg_replace("/(?<=$k X )\d+/e", '$0 + 5', $qq);<br />
Copy after login
一年级 X 2, 二年级 X 15 ,三年级 X 5 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!