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.

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

  • 相关阅读:
    MySQL初步
    学会编写Android Studio插件 别停留在用的程度了
    IDEA创建Java项目并配置servlet
    nginx 安装
    推荐博主
    ssh调试及指定私钥
    程序员接私活必备的 10 个开源项目
    springboot项目搭建java项目后台框架
    JAVA程序员常用网站/工具集合
    linux安装JDK教程JAVA相关
  • 原文地址:https://www.cnblogs.com/zhangjun516/p/3088624.html
Copyright © 2011-2022 走看看