douhui9380 2015-08-02 14:23
浏览 26
已采纳

如何在数组中搜索时计算值

I need some help with my PHP script. I want to add the value in each time when it add up to each value using id=row1-VALUE

Example:

row1-1
row1-2
row1-3
..etc

Using this code:

$program_title = $html->find('li[id=row1-1]', 0)->plaintext;

Here is the full code:

$base = $row['links'];

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);


// Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($str);

$channel_name = $_GET['channels'];
$show_id = 1;


$program_title = $html->find('li[id=row1-1]', 0)->plaintext;
?>

Can you please show me an example of how i can add the value next to the row1- to count up the value in each time and if the row1-20 or whatever it is that do not exist then I want to skip it to row2-1?

  • 写回答

1条回答 默认 最新

  • drau67562 2015-08-02 15:04
    关注

    Use nested for loop to accomplish this:

    for ($i = 1; $i <= 5; $i++) {
        for ($j = 1; $j <= 5; $j++) {
            $program_title = $html->find("li[id=row$i-$j]", 0)->plaintext;
            if (!empty($program_title)) {
                // The value exists
            } else
                break;
        }
    }
    

    Note: Replace number 5 with the limit you have for rows.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置