PHP php 跳出foreach循环问题

在10个鸡蛋上坐了3星期后,终于成功孵化出第一颗鸡蛋。
但礼仪小姐、导购小姐依然是场内的一道风景线。
声明:本文由入驻搜狐公众平台的作者撰写,除搜狐官方账号外,观点仅代表作者本人,不代表搜狐立场。
  基本就是2个大数组不停的循环算权重。
  &?php error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT); class weight { private $_aItems = array(); private $_aTable = array(); private $_aDict = array(); private $_aMatchs = array(); private $_aShow = array(); function __construct() { } public function newItems($aItems){ //添加新的检索内容 if (!is_array($aItems)) $aItems = (array)$aI $this-&_aItems = $aI $this-&_aMatchs = array(); $this-&_aShow = array(); } public function newTable($aTable){ if (!is_array($aTable)) $aTable = (array)$aT $this-&_aTable = $aT $this-&generateDict(); } private function generateDict() { //将字典处理成数组形式 $convert = function($value) { $value = str_replace('|', ',', $value); $value = explode(',', $value); return $ }; $this-&_aDict = array_map($convert, $this-&_aTable); } public function getMatchs() { //返回对照表 return $this-&_aM } public function getShow($sRule = 'debug') { /*返回格式化的结果集 * $sFormat: 指定输出格式 */ if (empty($this-&_aItems)||empty($this-&_aTable)) //字典源文件不存在 if (empty($this-&_aShow)) { /*匹配表还没有生成,自动调用相应的命令生成*/ $this-&loopTable(); } $makeDumpStr = function($value, $key) use (&$dumpStr) { //生成导出文件的文本 if (count($value) &1) { foreach ($value as $valueOne) { $valueStr .= $valueOne. ','; } $dumpStr .= $this-&_aItems[$key] . &\t匹配多个记录号\t&. $valueStr .&\r\n&; } else { $dumpStr .= $this-&_aItems[$key] . &\t匹配惟一记录号\t&. $value[0] .&\r\n&; } }; switch($sRule) { case 'debug': print_r($this-&_aShow); case 'json': return json_encode($this-&_aShow); case 'txt': $timeExport = date(&Y/M/D h:i:s&); $dumpStr = ''; $rFile = fopen('dump.txt', 'w'); array_walk($this-&_aShow, $makeDumpStr); $sContent = &&&EOT ========DUMP-FILE-{$timeExport}========================= {$dumpStr} EOT; fwrite($rFile, $sContent); fclose($rFile); default: return $this-&_aS } } private function loopTable() { //遍历 foreach ($this-&_aItems as $iItemKey=& $sItemLine) { $this-&matchElement($iItemKey); //print_r($this-&_aMatchs); $this-&match2Show($iItemKey); //print_r($this-&_aShow); //echo &-----------------&; } //print_r($this-&_aMatchs); //print_r($this-&_aShow); } private function matchElement($iKey) { $iMax = 0; foreach ($this-&_aDict as $iDictKey =& $aDictLine) { foreach($aDictLine as $sDictElement) { $str = $this-&_aItems[$iKey]; if(strstr($str, $sDictElement)){ //匹配到一个元素,计数器+1 ++$this-&_aMatchs[$iKey]['keyring'][$iDictKey]; } } if (!$this-&_aMatchs[$iKey]['keyring'][$iDictKey]) { //没有匹配到内容 $this-&_aMatchs[$iKey]['keyring'][$iDictKey] = 0; } if ($iMax& $this-&_aMatchs[$iKey]['keyring'][$iDictKey]) $iMax = $this-&_aMatchs[$iKey]['keyring'][$iDictKey]; $this-&_aMatchs[$iKey]['index'] = array( 'key' =& $iDictKey, 'count' =& $iMax ); } } private function match2Show($iKey) { //将对照表转化为结果集 $multiMatch = array(); //echo &ikey =&. $iKey.&, &; foreach ($this-&_aMatchs[$iKey]['keyring'] as $iMatchKey =& $iVal) { if ($iVal& $this-&_aMatchs[$iKey]['index']['count']) { //这个值比最大值小 //echo &x&; } else { //这个值跟最大值相等,将结果累加到记录中 //echo &y&; $multiMatch[] = $iMatchK } } if (count($multiMatch)& 1) //多于一条记录匹配值相同 $this-&_aShow[$iKey] = $multiM else //匹配值最大值唯一 $this-&_aShow[$iKey] = array($this-&_aMatchs[$iKey]['index']['key']); } } $aItems = array( 'chinaisbig', 'whichisnot', ..... 上万条 ..... 'totalyrightforme', ); $aTable = array( 'china,is|small', 'china,big|me', ..... 上千条 ..... 'china,is|big,wich|not,me', ); $weight = new weight(); $weight-&newItems($aItems); $weight-&newTable($aTable); $weight-&getShow('debug'); ?&
欢迎举报抄袭、转载、暴力色情及含有欺诈和虚假信息的不良文章。
请先登录再操作
请先登录再操作
微信扫一扫分享至朋友圈
搜狐公众平台官方账号
生活时尚&搭配博主 /生活时尚自媒体 /时尚类书籍作者
搜狐网教育频道官方账号
全球最大华文占星网站-专业研究星座命理及测算服务机构
主要用于it编程人员的日常交流,经验分享,学习技术
主演:黄晓明/陈乔恩/乔任梁/谢君豪/吕佳容/戚迹
主演:陈晓/陈妍希/张馨予/杨明娜/毛晓彤/孙耀琦
主演:陈键锋/李依晓/张迪/郑亦桐/张明明/何彦霓
主演:尚格?云顿/乔?弗拉尼甘/Bianca Bree
主演:艾斯?库珀/ 查宁?塔图姆/ 乔纳?希尔
baby14岁写真曝光
李冰冰向成龙撒娇争宠
李湘遭闺蜜曝光旧爱
美女模特教老板走秀
曝搬砖男神奇葩择偶观
柳岩被迫成赚钱工具
大屁小P虐心恋
匆匆那年大结局
乔杉遭粉丝骚扰
男闺蜜的尴尬初夜
客服热线:86-10-
客服邮箱:PHP生成字符串问题,带循环的
本回答由提问者推荐
var sogou_ad_id=731547;
var sogou_ad_height=160;
var sogou_ad_width=690;

我要回帖

更多关于 php跳出循环 的文章

 

随机推荐