首页 > 后端开发 > php教程 > php数组传值调用与传址调用

php数组传值调用与传址调用

WBOY
发布: 2016-07-25 08:53:29
原创
1156 人浏览过
  1. public class ArrayTest {

  2. public static void main(String[] args){
  3. Map[] maparray=new Map[3];
  4. for (int i = 0; i Map map=new HashMap();
  5. map.put("a", i+"_ajkcz");
  6. map.put("c", "werq_"+i);
  7. maparray[i]=map;
  8. }
  9. System.out.println("++++++++++++++++++++++++");
  10. for (int i = 0; i Map map=maparray[i];
  11. Iterator it=map.keySet().iterator();
  12. while(it.hasNext()){
  13. String key=(String) it.next();
  14. System.out.println(key+"\t"+map.get(key) );
  15. }
  16. }
  17. System.out.println("++++++++++++++++++++++++");
  18. new ArrayCharge().printAndChangeArray(maparray);
  19. System.out.println("++++++++++++++++++++++++");
  20. for (int i = 0; i Map map=maparray[i];
  21. Iterator it=map.keySet().iterator();
  22. while(it.hasNext()){
  23. String key=(String) it.next();
  24. System.out.println(key+"\t"+map.get(key) );
  25. }
  26. }
  27. }
  28. }
  29. class ArrayCharge {

  30. public void printAndChangeArray(Map[] maparray){
  31. for (int i = 0; i Map map=maparray[i];
  32. map.put("a",i+"________");
  33. }
  34. for (int i = 0; i Map map=maparray[i];
  35. Iterator it=map.keySet().iterator();
  36. while(it.hasNext()){
  37. String key=(String) it.next();
  38. System.out.println(key+"\t"+map.get(key) );
  39. }
  40. }
  41. }
  42. }
复制代码

控制台输出结果:

  1. $arraytest=array();
  2. for($i=0;$i $child=array();
  3. $child['keystr']='key'.$i;
  4. $child['valuestr']='value'.$i;
  5. $arraytest[]=$child;
  6. }
  7. print_r($arraytest);
  8. print_r("+++++++++++++++++++++++++");
  9. for($i=0;$i $child=$arraytest[$i];
  10. $child['valuestr']="_________".$i;
  11. }
  12. print_r($arraytest);
  13. print_r("+++++++++++++++++++++++++");
  14. ?>
复制代码

控制台输出:

  1. $arraytest=array();
  2. for($i=0;$i $child=array();
  3. $child['keystr']='key'.$i;
  4. $child['valuestr']='value'.$i;
  5. $arraytest[]=$child;
  6. }
  7. print_r($arraytest);
  8. print_r("+++++++++++++++++++++++++");
  9. for($i=0;$i $child=&$arraytest[$i]; //注意这里加了一个指针符号,代表是传址调用
  10. $child['valuestr']="_________".$i;
  11. }
  12. print_r($arraytest);
  13. print_r("+++++++++++++++++++++++++");
  14. ?>
复制代码

控制台输出:

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 ) )+++++++++++++++++++++++++


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板