Php array, php array Length
<? Php
$ Arr = array ('zz '=> 'zhengzhou', 'beijing', 9 => 'shanghai', 'zhengzhou ');
Print_r ($ arr );
$ C = array_unique ($ arr); // removes duplicate element values and performs index sorting.
Print_r ($ c );
$ B = array_values ($ arr); // sorts the array again.
Print_r ($ B );
$ Arr1 = array ('zhengzhou ', 'hebei', 'shanghai', 'beijing ');
$ Arr2 = array ('kaifeng ', 'luoyang', 'puyang ');
$ Arr3 = array_merge ($ arr1, $ arr2); // merges arrays $ arr1, $ arr2.
Echo '<pre> ';
Print_r ($ arr3 );
$ Str = "jjjjjj5555455ccccdddd565dfddfd ";
$ Arr = preg_split ('/\ d {1,}/', $ str); // Regular Expression
Print_r ($ arr );
$ St = "Beijing, Shanghai, Tianjin, Zhengzhou, Guangdong ";
$ Arr = explode (',', $ st );
Print_r ($ arr );
$ Ss = implode ("====", $ arr );
Echo '<pre> ';
Echo $ ss;
Foreach ($ arr as $ v ){
Echo '<pre> ';
Echo $ v;
}
$ Arr [] [] = 'OK ';
$ Arr [] [] = [10, 20, 30];
$ Arr [] [] = 'hello ';
$ Arr [] [] = array ('hn '=> 'henan', 60, 'zz '=> 'zhengzhou', array (100,200 ));
Echo '<pre> ';
Print_r ($ arr );
Echo $ arr [1] [0] [2];
$ Age = $ sage = $ stage = 50;
Echo $ age;
Echo '<pre> ';
Echo $ sage;
Echo $ stage;
// Two-dimensional array
$ Arr = array (10, 'zz '=> 'zhengzhou', array (20, 30, 40, 50), array (60, 70, 80 ));
Echo '<pre> ';
Print_r ($ arr );
Echo $ arr [2] [0];
Echo sizeof ($ arr, 1 );
Echo count ($ arr );
Foreach ($ arr as $ v ){
If (! Is_array ($ v )){
Echo $ v. '<br> ';
Continue;
}
Foreach ($ v as $ vv ){
Echo $ vv. '<br> ';
}
}
$ A = [10, 20, 30, 40];
Echo in_array (20, $ a); // query whether a value in the array exists. If yes, 1 is returned.
If (array_search (20, $ a) === false ){
Echo 'not found ';
} Else {
Echo 'found, Location:'. array_search (20, $ );
}
// We recommend that you specify the number of characters in the sequence.
$ Arr = range ('A', 'z ');
$ Arr = range (1,100, 3 );
Echo '<pre> ';
Print_r ($ arr );
Substr intercepts numeric values. in_array determines whether the value exists in the array.
$ Arr = array ('12', '123', '123', '123 ');
$ Aa = '000000 ';
If (in_array (substr ($ aa, 0, 2), $ arr )){
Echo 'exists'. $ aa;
} Else {
Echo 'nonexistent ';
}
Is_array: determines if it is an array.
$ Arr = 20;
If (is_array ($ arr )){
Echo 'is an array ';
Print_r ($ arr );
} Else {
Echo 'not an array ';
Echo $ arr;
}
// Use a loop statement to assign 10 values to an empty array (a random integer between 1 and)
$ Arr = array ();
For ($ I = 0; $ I <10; $ I ++ ){
$ Arr [] = mt_rand (1,100 );
}
Echo 'sorted :';
Foreach ($ arr as $ v ){
Echo $ v. '& nbsp ;';
}
Echo '
//// Implement the Sorting Algorithm Bubble Sorting
For ($ m = 0; $ m <count ($ arr)-1; $ m ++ ){
For ($ n = 0; $ n <count ($ arr)-1; $ n ++ ){
If ($ arr [$ n]> $ arr [$ n + 1]) {
$ T = $ arr [$ n];
$ Arr [$ n] = $ arr [$ n + 1];
$ Arr [$ n + 1] = $ t;
}
}
}
Echo 'sorted :';
Foreach ($ arr as $ v ){
Echo $ v. '& nbsp; & nbsp ';
}
$ Arr = array ();
$ Arr [] = 10;
$ Arr [] = 20;
$ Arr [] = 30;
$ Arr [] = 40;
$ Arr [] = 50;
Echo $ arr [2];
Echo rand (1, 3). ','. rand (). ','. rand (10,100); // Random Number
Echo mt_rand (1,100). '--'. mt_rand (). '--'. mt_rand (); // generate a better random number.
// Declare an array and assign a random integer in the range of 10 numbers (1-100)
$ Arr = array ();
For ($ I = 0; $ I <10; $ I ++ ){
$ Arr [] = mt_rand (1,100 );
}
Echo '<pre> ';
Print_r ($ arr );
Sort ($ arr); // output array after sorting
Print_r ($ arr );
$ Arr1 = array (,); // declare an array
$ Arr2 = [10, 20, 30];
$ Arr3 = array ('bj '=> 'beijing', 'sh' => 'shanghai ');
Echo '<pre> ';
Var_dump ($ arr1); // print the array and output type
Print_r ($ arr3); // print the output Array
Echo $ arr3 ['bj ']; // output to Beijing
Echo '<br> ';
Echo $ arr1 [2];/output 30, starting from 0
Foreach ($ arr3 as $ k =>$ v ){
Echo $ v; // output value, $ k output subscript
}
$ Arr3 [] = 'zhengzhou '; // add elements to the array following the Array
$ Arr3 ['sz '] = 'shenzhen ';
Array_unshift ($ arr3, 'hangzhou', 'qingdao '); // Add an element before the Array
Unset ($ arr3 ['bj ']); // deletes the bj element in the $ arr3 Array
$ Bj = array_shift ($ arr3); // remove the first element from the array, assign it to bj, and output
Echo $ bj;
$ Sz = array_pop ($ arr3); // removes the last element from the array and assigns a value
Echo $ sz;
Foreach ($ arr3 as $ k =>$ v ){
Echo $ k. '=>'. $ v;
}
Sort ($ arr1); // ascending, from small to large
Rsort ($ arr1); // descending order, from large to small
Print_r ($ arr1 );
Echo count ($ arr1 );
$ A = array (4, 8 );
Echo count ($ a); // returns the number of elements in the array 2
$ Str = 'day, one, two, three, four, five, six ';
$ Arr = explode (',', $ str); // Splits a string into arrays based on the string interval.
// Print_r ($ arr );
$ W = date ('W ');
Echo 'Today is: week'. $ arr [$ w];
$ H = date ('G ');
// If ($ h >=8 & $ h <= 12 ){
// Echo 'Good morning ';
//} Else if ($ h >=13 & $ h <= 18 ){
// Echo 'good afternoon ';
//} Else if ($ h >=19 & $ h <= 21 ){
// Echo 'Good evening ';
//} Elseif ($ h >=22 & $ h <= 6 ){
// Echo 'late at night, please take a rest ';
//} Elseif ($ h >=6 & $ h <= 7 ){
// Echo 'Good morning ';
//}
// Echo date ('Y-m-d H: I: s ');
// $ D = date ('W ');
// If ($ d = 0 ){
// Echo 'today: Sunday ';
//}
// If ($ d = 1 ){
// Echo 'today: Monday ';
//}
// If ($ d = 2 ){
// Echo 'today: Tuesday ';
//}
// If ($ d = 3 ){
// Echo 'today: weday ';
//}
// If ($ d = 4 ){
// Echo 'today: thurs ';
//}
// If ($ d = 5 ){
// Echo 'today: Friday ';
//}
// If ($ d = 6 ){
// Echo 'today: saturday ';
//}
?>