• PassArrayByCopy_test.php


    <?php
    //PassArrayByCopy_test.php
    $a=array("a","b","c");
    function test(array $p)
    {
        $len=count($p);
        for($i=0;$i<$len;$i++)
        {
            $p[$i]='Ex~' . $p[$i];
        }
        echo 'in function test:<br>';
        var_dump($p);
        echo 'leave function test.<br>';
    }
    
    var_dump($a);
    test($a);
    var_dump($a);
    echo '<hr>';
    function test2()
    {
        global $a;
        $len=count($a);
        for($i=0;$i<$len;$i++)
        {
            $a[$i]='Ex~' . $a[$i];
        }
        echo 'in function test2:<br>';
        var_dump($a);
        echo 'leave function test2.<br>';
    }
    
    test2();
    var_dump($a);
    
    ?>
    array (size=3)
      0 => string 'a' (length=1)
      1 => string 'b' (length=1)
      2 => string 'c' (length=1)
    in function test:
    array (size=3)
      0 => string 'Ex~a' (length=4)
      1 => string 'Ex~b' (length=4)
      2 => string 'Ex~c' (length=4)
    leave function test.
    array (size=3)
      0 => string 'a' (length=1)
      1 => string 'b' (length=1)
      2 => string 'c' (length=1)
    in function test2:
    array (size=3)
      0 => string 'Ex~a' (length=4)
      1 => string 'Ex~b' (length=4)
      2 => string 'Ex~c' (length=4)
    leave function test2.
    array (size=3)
      0 => string 'Ex~a' (length=4)
      1 => string 'Ex~b' (length=4)
      2 => string 'Ex~c' (length=4)
    array (size=3)
      0 => 

    string

     'a' (length=1)
      1 => 

    string

     'b' (length=1)
      2 => 

    string

     'c' (length=1)
    

    in function test:

    array (size=3)
      0 => 

    string

     'Ex~a' (length=4)
      1 => 

    string

     'Ex~b' (length=4)
      2 => 

    string

     'Ex~c' (length=4)
    

    leave function test.

    array (size=3)
      0 => 

    string

     'a' (length=1)
      1 => 

    string

     'b' (length=1)
      2 => 

    string

     'c' (length=1)
    

    in function test2:

    array (size=3)
      0 => 

    string

     'Ex~a' (length=4)
      1 => 

    string

     'Ex~b' (length=4)
      2 => 

    string

     'Ex~c' (length=4)
    

    leave function test2.

    array (size=3)
      0 => 

    string

     'Ex~a' (length=4)
      1 => 

    string

     'Ex~b' (length=4)
      2 => 

    string

     'Ex~c' (length=4)
  • 相关阅读:
    python学习----8.28---单例模式,网络编程
    python学习-----8.27----异常处理,元类
    python学习--8.23
    python学习-----8.22--classmethod和staticmethod
    Python学习---8.21组合,多态,封装
    python学习----8.20面向对象---继承与派生
    Python学习----8.17--面向对象编程
    python成长之旅 一
    python java php语言之间的对比
    python成长之旅
  • 原文地址:https://www.cnblogs.com/sky20080101/p/7076818.html
Copyright © 2020-2023  润新知