php數組傳值調用與傳址調用

來源:互聯網
上載者:User
  1. public class ArrayTest {

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

  32. class ArrayCharge {

  33. public void printAndChangeArray(Map[] maparray){
  34. for (int i = 0; i < maparray.length; i++) {
  35. Map map=maparray[i];
  36. map.put("a",i+"________");
  37. }
  38. for (int i = 0; i < maparray.length; i++) {
  39. Map map=maparray[i];
  40. Iterator it=map.keySet().iterator();
  41. while(it.hasNext()){
  42. String key=(String) it.next();
  43. System.out.println(key+"\t"+map.get(key) );
  44. }
  45. }
  46. }
  47. }
複製代碼

控制台輸出結果:

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

控制台輸出:

  1. $arraytest=array();
  2. for($i=0;$i<3;$i++){
  3. $child=array();
  4. $child['keystr']='key'.$i;
  5. $child['valuestr']='value'.$i;
  6. $arraytest[]=$child;
  7. }
  8. print_r($arraytest);
  9. print_r("+++++++++++++++++++++++++");
  10. for($i=0;$i $child=&$arraytest[$i]; //注意這裡加了一個指標符號,代表是傳址調用
  11. $child['valuestr']="_________".$i;
  12. }
  13. print_r($arraytest);
  14. print_r("+++++++++++++++++++++++++");
  15. ?>
複製代碼

控制台輸出:

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 ) )+++++++++++++++++++++++++
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.