The call to an array in Java is called by default: The Principal method passes an array to a method in which a value of the array is modified, and the array is found to be changed back to the main method;
Test Code:
public class Arraytest {public static void main (string[] args) {map[] maparray=new map[3];for (int i = 0; i < MAPARRAY.L Ength; i++) {map<string,string> map=new hashmap<string,string> () 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<string,string> 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<string,string> 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<string,string> map=maparray[i];map.put ("A", i+ "________");} for (int i = 0; i < maparray.length; i++) {map<string,string> map=maparray[i];iterator it=map.keyset (). Iterator ( ); while (It.hasnext ()) {string key= (String) it.next (); System.out.println (key+ "\ T" +map.get (key));}}} Console output: ++++++++++++++++++++++++cwerq_0a0_ajkczcwerq_1a1_ajkczcwerq_2a2_ajkcz++++++++++++++++++++++++cwerq_0a0 ________cwerq_1a1________cwerq_2a2________++++++++++++++++++++++++cwerq_0a0________cwerq_1a1________cwerq_2a2_ _______
In PHP, the invocation of an array is called by default, and the array is modified in the Word method, which cannot be detected in the parent method.
Test Code:
<?php $arraytest =array (); for ($i =0; $i <3; $i + +) {$child =array (); $child [' Keystr ']= ' key '. $i; $child [' Valuestr ']= ' Value '. $i; $arraytest []= $child;} Print_r ($arraytest);p rint_r ("+++++++++++++++++++++++++"); for ($i =0; $i <count ($arraytest); $i + +) {$child =$ arraytest[$i]; $child [' Valuestr ']= ' _________ '. $i;} Print_r ($arraytest);p rint_r ("+++++++++++++++++++++++++");? >
Console output:
Array ([0] = = Array ( [keystr] = Key0 [valuestr] = VALUE0) [1] = = Array ([KEYSTR] = Key1 [val UESTR] = value1) [2] = = Array ([keystr] = Key2 [VALUESTR] = value2)) +++++++++++++++++++++++++array ([ 0] = = Array ([KEYSTR] = Key0 [VALUESTR] = VALUE0) [1] = = Array ([KEYSTR] = Key1 [VALUESTR] = Valu E1) [2] = = Array ([keystr] = Key2 [VALUESTR] = value2)) +++++++++++++++++++++++++
If you want to be in PHP also similar to the Java in the array parameter to the Word method, the Word method processing completion stepfather method array also follow the change will need to pass the parameter when the value is passed instead of the value of the pointer, for example, the value of P is 100, that is, $p=100; The argument that is passed when the P method is passed is & $p "
Test code:
<?php $arraytest =array (); for ($i =0; $i <3; $i + +) {$child =array (); $child [' Keystr ']= ' key '. $i; $child [' Valuestr ']= ' Value '. $i; $arraytest []= $child;} Print_r ($arraytest);p rint_r ("+++++++++++++++++++++++++"); for ($i =0; $i <count ($arraytest); $i + +) {$child =&$ arraytest[$i]; Note that a pointer symbol is added here, which represents the address call $child[' valuestr ']= "_________". $i;} Print_r ($arraytest);p rint_r ("+++++++++++++++++++++++++");? >
Console output:
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))