久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      php數組怎么去除負數

      方法:1、用foreach遍歷數組,語法“foreach($arr as $k=>$v){}”;2、在循環(huán)體中,判斷數組元素“$v”是否為負數,如果是負數則用unset()刪除,語法“if($v<0){unset($arr[$k]);}”。

      php數組怎么去除負數

      本教程操作環(huán)境:windows7系統、PHP7.1版、DELL G3電腦

      php數組去除負數的方法

      1、使用foreach語句遍歷數組

      foreach ($array as $key => $value){     語句塊; }

      遍歷給定的 $array 數組,在每次循環(huán)中會將當前數組的值賦給 $value,鍵名賦給 $key。

      2、在循環(huán)體中,去除負數

      在循環(huán)體中,判斷數組元素值是否為負數(即是否小于0),如果是負數,則使用unset()刪除該元素。

      if($value<0){ 	unset($array[$key]); }

      實現代碼:

      <?php header('content-type:text/html;charset=utf-8');    $arr = [3,-1,4,6,-5,7,-3]; var_dump($arr); foreach($arr as $k=>$v){ 	if($v<0){ 		unset($arr[$k]); 	} } var_dump($arr); ?>

      php數組怎么去除負數

      推薦學習:《PHP視頻教程》

      贊(0)
      分享到: 更多 (0)
      網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號