php數組傳值呼叫與傳址調用
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-07-25 08:53:29
-
-
public class ArrayTest {
- public static void main(String[] args){
- Map[] maparray=new Map[3];
- for (int i = 0; i < maparray.length; i ) {
- Map map=new HashMap();
- map.put("a", i "_ajkcz");
- map.put("c", "werq_" i);
- maparray[i]=map;
- }
-
- System.out.println(" ");
- for (int i = 0; i < maparray.length; i ) {
- Map map=maparray[i];
- Iterator it=map.keySet().iterator();
- while(it.hasNext()){
- String key=(String) it.next();
- System.out.println(key "t" map.get(key) );
- }
- }
-
- System.out.println(" ");
- new ArrayCharge().printAndChangeArray(maparray);
-
-
- System.out.println(" ");
- for (int i = 0; i < maparray.length; i ) {
- Map map=maparray[i];
- Iterator it=map.keySet().iterator();
- while(it.hasNext()){
- String key=(String) it.next();
- System.out.println(key "t" map.get(key) );
- }
- }
- }
- }
class ArrayCharge {
- public void printAndChangeArray(Map[] maparray){
- for (int i = 0; i < maparray.length; i ) {
- Map map=maparray[i];
- map.put("a",i "________");
- }
-
- for (int i = 0; i < maparray.length; i ) {
- Map map=maparray[i];
- Iterator it=map.keySet().iterator();
- while(it.hasNext()){
- String key=(String) it.next();
- System.out.println(key "t" map.get(key) );
- }
- }
- }
- }
-
-
复制代码
控制台输出结果:
-
- $arraytest=array();
- for($i=0;$i<3;$i ){
- $child=array();
- $child['keystr']='key'.$i;
- $child['valuestr']='value'.$i;
- $arraytest[]=$child;
- }
-
- print_r($arraytest);
-
- print_r(" ");
- for($i=0;$i $child=$arraytest[$i];
- $child['valuestr']="_________".$i;
- }
-
-
- print_r($arraytest);
-
- print_r(" ");
-
- ?>
-
复制代码
控制台输出:
-
- $arraytest=array();
- for($i=0;$i<3;$i ){
- $child=array();
- $child['keystr']='key'.$i;
- $child['valuestr']='value'.$i;
- $arraytest[]=$child;
- }
-
- print_r($arraytest);
-
- print_r(" ");
- for($i=0;$i $child=&$arraytest[$i]; //注意这里加了一个指针符号,代表是传址调用
- $child['valuestr']="_________".$i;
- }
-
- print_r($arraytest);
- print_r(" ");
- ?>
-
复制代码
控制台输出:
Array (
[0] => Array (
[keystr] => key0
[valuestr] => value0
)
[1] => Array (
[keystr] => key1
[valuestr] => value1
)
[2] => Array (
[keystr] => key2
[valuestr] => value2
)
)
Array (
[0] => Array (
[keystr] => key0
[valuestr] => _________0
)
[1] => Array (
[keystr] => key1
[valuestr] => _________1
)
[2] => Array (
[keystr] => key2
[valuestr] => _________2
)
) |
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
最新問題
-
2025-03-26 19:48:00
-
2025-03-26 19:40:08
-
2025-03-26 12:24:37
-
2025-03-26 12:20:46
-
2025-03-21 13:39:34