The foreach loop of the two-dimensional array numeric string cannot be compared with a number. Try to convert it to an int type and the result will directly become 0.
焚天驻地
焚天驻地 2017-09-29 16:31:48
0
6
1499

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("/]*>/","", $res); $str2 = preg_replace("/<\/a>/","", $str1); preg_match('/]*? class="tab01">(.*?)<\/table>/s',$str2,$match); preg_match_all('/.*?<\/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 '
'; var_dump($leftfoot); echo '
'; var_dump((int)$leftfoot); //强制转换为整型 数据变成0 //获取满足条件的数据重组数组 if($leftfoot >= 10 && $leftfoot<=50){ //不转换数据类型无法比较大小 $left_10to50_arr[]=$vals; } if($keys>3)exit; } echo '
'; print_r($left_10to50_arr); echo '
'; exit;

The two-dimensional array format is as follows:

QQ图片20170929162436.png

After the numeric characters are converted, they become 0. The situation is as follows:

QQ截图20170929162647.jpg


焚天驻地
焚天驻地

reply all (6)
朽木

What does it mean not enough beans? The dear friend above, p bean?

    phpcn_u38476

    333

      phpcn_u38476

      44444444444444433333333333

        phpcn_u38476

        Want 1 bean 2 bean 3 bean 0 bean 0 bean - want = bean 43 bean 2 bean 2 bean 4 bean 4 bean

          phpcn_u38476

          Not enough beans, not enough beans, not enough beans, not enough beans, not enough beans, not enough beans, not enough beans

            phpcn_u38476

            Not enough beans, not enough beans, not enough beans, not enough beans, not enough beans, not enough beans

              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!