PHP fun Development 1

Source: Internet
Author: User
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 )?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.