Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does php make a fixed-length array?
How does php make a fixed-length array?
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

//php imitates java fixed-length arrays: int [] source = new int [10];

$ source = new SplFixedArray( 10);

//$ source[ 10]= 1; This will report an error because it is beyond the boundary of the array, and the maximum subscript of $source is 9.

//Imitate java and assign the default value of 0 to the array elements.

for($ I = 0; $ i & ltsizeof($ source); $i++) {

$ source[$ I]= 0;

}

//The expansion of the array is 1.5 times of the original.

$ size = sizeof($ source);

$ destination = new SplFixedArray($ size+($ size & gt; & gt 1));

for($ I = 0; $ i & ltsizeof($ source); $i++) {

$ destination[$ I]= $ source[$ I];

}

print _ r($ destination);