PassArrayByCopy_test.php

Posted sky20080101

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

 





以上是关于PassArrayByCopy_test.php的主要内容,如果未能解决你的问题,请参考以下文章

R留学生作业代码代写代编程代编程代编程

IPEX-1代/3代/4代/5代,PCB天线底座,公头,样式及封装尺寸图

JVM 年轻代 老年代 持久代 gc

深圳本地网店代运营公司

C线程代业代写代调试POSIX Threads代编码

jvm中的年轻代 老年代 持久代 gc