Problem description: foreach loops the two-dimensional array to find content that meets the conditions and reorganizes it into a new two-dimensional array. The obtained digital string is compared with the number, and the comparison cannot be made. Try to convert the digital characters to int type, and all the results become into 0; (the following code can be run directly)
//创建curl资源 $ch=curl_init(); //设置url和对应项 curl_setopt($ch, CURLOPT_URL, "http://match.sports.sina.com.cn/football/csl/opta_rank.php?item=shoot&year=2014&lid=8&type=1&dpc=1"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //以文件形式返回而不是直接输出 $data=curl_exec($ch); $my_file=fopen("shoot.html",'w') or die('no file'); fwrite($my_file, $data); fclose($my_file); curl_close($ch); $my_file=fopen("shoot.html",'r'); $res= fread($my_file,filesize("shoot.html")); fclose($my_file); //步骤2获取table内容转为数组 $str1 = preg_replace("/<a[^>]*>/","", $res); $str2 = preg_replace("/<\/a>/","", $str1); preg_match('/<table[^>]*? class="tab01">(.*?)<\/table>/s',$str2,$match); preg_match_all('/<td.*?>.*?<\/td>/i',$match[0],$e1); foreach ($e1[0] as $k=>$v){ $shoot_arr[ceil(($k+1)/8)-1][]=$v; } shuffle($shoot_arr); //随机排序 $left_10to50_arr=array(); //var_dump($shoot_arr); foreach($shoot_arr as $keys=>$vals){ // $leftfoot=$shoot_arr[$keys][4]; echo '<br/>'; var_dump($leftfoot); echo '<br/>'; var_dump((int)$leftfoot); //强制转换为整型 数据变成0 //获取满足条件的数据重组数组 if($leftfoot >= 10 && $leftfoot<=50){ //不转换数据类型无法比较大小 $left_10to50_arr[]=$vals; } if($keys>3)exit; } echo '<pre>'; print_r($left_10to50_arr); echo '</pre>'; exit;
The two-dimensional array format is as follows:
After the numeric characters are converted, they become 0. The situation is as follows:
phpcn_u384762017-10-02 23:22:52
Want 1 bean 2 bean 3 bean 0 bean 0 bean - want = bean 43 bean 2 bean 2 bean 4 bean 4 bean
phpcn_u384762017-10-02 23:14:58
Not enough beans, not enough beans, not enough beans, not enough beans, not enough beans, not enough beans, not enough beans
phpcn_u384762017-10-02 23:14:40
Not enough beans, not enough beans, not enough beans, not enough beans, not enough beans, not enough beans