PHP interesting development I recently had plenty of time. I used PHP to implement a few interesting things and shared them with me: & lt ;? Php/*** php draw a diamond ** train of thought: how many lines for once, then spaces and markup characters for once in it. ** @ Authorflyer0126 * @ date201 PHP fun Development 1
There has been plenty of time recently. I have used PHP to implement several interesting things and share them with me:
";}// Lower half for ($ I = 1; $ I <10; $ I ++) {for ($ j = 0; $ j <$ I; $ j ++) {echo "" ;}for ($ k = (18-2 * $ I + 1); $ k> 0; $ k --) {echo "'";} echo"
";}/*** PHP implementation of Yang Hui triangle ** idea: the first and last bits in each line are 1, which has not changed, in the middle is the sum of one row in the front row and one row on the left. this algorithm is saved in a two-dimensional array and output in one row. * 1 1 1 1 2 1 3 3 1 4 6 4 1 1 5 10 10 5 1 ** @ author flyer0126 * @ date 2011-12-09 ** // variable initialization $ arr = array (); // Set the fixed value 1for ($ I = 0; $ I <6; $ I ++) {$ arr [$ I] [0] = 1; $ arr [$ I] [$ I] = 1;} // calculates the median for ($ I = 2; $ I <6; $ I ++) {for ($ j = 1; $ j <$ I; $ j ++) {$ arr [$ I] [$ j] = $ arr [$ i-1] [$ j-1] + $ arr [$ i-1] [$ j];} // arrange the output for ($ I = 0; $ I
";}/*** In a set of numbers, you must insert a number in the original order to maintain the original sorting method. ** Idea: find the location that is larger than the number to be inserted, replace it, and then move the following number one. ** @ Author flyer0126 * @ date 2011-12-08 ** // initialize the array variable (ascending) $ arr = array (1, 3, 5, 7, 9 ); // Insert 6for ($ I = 0; $ I
$ J + 1 )? $ Tmp2 = $ arr [$ j]: ''; $ arr [$ j] = $ tmp1; $ tmp1 = $ tmp2;} break ;}} // output print_r ($ arr ); // Array ([0] => 1 [1] => 3 [2] => 5 [3] => 6 [4] => 7 [5] => 9 )?>