Home > Backend Development > PHP Tutorial > 怎么劈开一组数字中的4与7

怎么劈开一组数字中的4与7

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:19:09
Original
1079 people have browsed it

如何劈开一组数字中的4与7
例如一组数字:3655448674
需要避开这组数字中的4与7,遇到则++

<br />$strMaxcardid=3655448674;<br />$ar = str_split($strMaxcardid);<br /><br />		foreach($ar as $k => $v) {<br />			<br />    	if ($v == 4 || $v == 7) { <br />           $ar[$v] ++;       <br />            break;    <br />        }}<br />  		$str = join('', $ar);<br />  		echo $str;*/<br />
Copy after login

这样的写法并不能避免多个7与4的出现,求高手指点下
------解决思路----------------------
1、$ar[$v] ++; 应为 $k++
2、break; 不要,发现一个就跳出循环,怎么能处理多个?
$strMaxcardid=3655448674;<br />$ar = str_split($strMaxcardid);<br /> <br />foreach($ar as $k => $v) {<br />  if ($v == 4 <br><font color='#FF8000'>------解决思路----------------------</font><br> $v == 7) { <br />    $ar[$k] ++;       <br />  }<br />}<br />$str = join('', $ar);<br />echo $str;
Copy after login
3655558685

Related labels:
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