PHP删除foreach循环中的数组

时间:2018-03-12 12:52:12

标签: php arrays loops foreach unset

所以我试图在foreach循环中的if语句中删除数组...

<?php
        foreach ($politics as $tag => $key):?>


        <?php    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
                    $ip = $_SERVER['HTTP_CLIENT_IP'];
                    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
                    } else {
                        $ip = $_SERVER['REMOTE_ADDR'];
                      }
                      $vienodas = "SELECT * FROM pol WHERE (politikas = '$Veryga' AND ip = '$ip')";
                      $vienodasres = mysqli_query($conn, $vienodas);
                     if ( mysqli_num_rows($vienodasres) > 0){
                         //IT DOESN'T WORK 
                         unset($politics[$tag]);
                         //IT DOESN'T WORK 
                     }
                      ?>
 <div class="mySlides">
<?php $Veryga= $key['vardas'];
 $Veryga2 = str_replace(' ', '', $Veryga);
 ?>
  <div <?php echo 'id="'.$Veryga2.'"'; ?> class="politikai">

<..Not important code..>



  </div>
  <?php
  endforeach; ?>

它不想工作,我试图这样做,if语句只检查是否有等于用户IP的行和它们的幻灯片

2 个答案:

答案 0 :(得分:1)

你有错误方式的值和关键元素应该像这样定义。

UIViewController

答案 1 :(得分:0)

您之后没有访问该$politics数组元素,因此未设置,但控制流在元素内继续。 如果你想阻止输出在那时使用continue;语句。