zoukankan      html  css  js  c++  java
  • php unset

    php里面的unset 可以把值置空,但是并不会改变值已经有的索引位置

     1 $testArr=array('frist','second','third');
     2 echo '<pre>';
     3 echo '<br/>---------------------------------proto ------------------------------</br>';
     4 print_r($testArr);
     5 foreach($testArr as $key=>$val){
     6     unset($testArr[$key]);
     7 }
     8 echo '<br/>---------------------opo---------------------------</br>';
     9 print_r($testArr);
    10 $testArr[]='good!';
    11 echo '<br/>---------------------add---------------------------</br>';
    12 print_r($testArr);
    13 echo '</pre>';

    If a static variable is unset() inside of a function, unset() destroys the variable only in the context of the rest of a function. Following calls will restore the previous value of a variable.

     1 function foo()
     2 {
     3     static $bar;
     4     $bar++;
     5     echo "Before unset: $bar, ";
     6     unset($bar);
     7     $bar = 23;
     8     echo "after unset: $bar<br/>";
     9 }
    10 
    11 foo();
    12 foo();
    13 foo();
    14 


    vld分析: 15 function foos(&$bar) 16 { 17 unset($bar); 18 $bar = "blah"; 19 } 20 21 $bar = 'something'; 22 echo "$bar<br/>"; 23 24 foos($bar); 25 echo "$bar<br/>";


    
    

    If a variable that is PASSED BY REFERENCE is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.

    这是手册中发现的,突然感觉把手册再翻一遍,是个正确的选择

  • 相关阅读:
    html-----vedio标签(HTML5新标签VIDEO在IOS上默认全屏播放)
    JS---控制键盘事件
    js事件监听-addEventListener (w3c标准) 和 attachEvent(ie)
    html5 -----audio标签
    花点时间搞清top、clientTop、scrollTop、offsetTop
    vue手机端横屏竖屏切换
    spring事务
    跨域
    java8 lambda 与 stream
    vueAdmin使用动态路由时踩坑
  • 原文地址:https://www.cnblogs.com/zhangjun516/p/3088624.html
Copyright © 2011-2022 走看看