PHP异趣开发一

Jun 13, 2016 am 10:41 AM
arr echo for gt lt

PHP趣味开发一

最近时间有些充裕,利用PHP实现了几个有意思的东东,拿来分享一下:

<?php /** * php画个菱形 *  * 思路:多少行for一次,然后在里面空格和标记符号for一次。 *  * @author flyer0126 * @date 2011-12-09 *  *///上半部分for ($i=0; $i<10; $i++){	for ($j=0; $j<9-$i; $j++){		echo " ";	}	for ($k=0; $k<(2*$i+1); $k++){		echo "`";	}	echo "<br/>";}//下半部分for ($i=1; $i0; $k--){		echo "`";	}	echo "<br>";}/** * PHP实现杨辉三角 *  * 思路:每一行的第一位和最后一位是1,没有变化,中间是前排一位与左边一排的和,这种算法是用一个二维数组保存,一行一行的输出。 * 1   1 1   1 2 1   1 3 3 1   1 4 6 4 1   1 5 10 10 5 1 * * @author flyer0126 * @date 2011-12-09 *  *///变量初始化$arr = array();//设置固定值1for ($i=0; $i";}/** * 在一组数中,要求插入一个数,按其原来顺序插入,维护原来排序方式。 *  * 思路:找到比要插入数大的那个位置,替换,然后把后面的数后移一位。 *  * @author flyer0126 * @date 2011-12-08 *  *///初始化数组变量(升序)$arr = array(1, 3, 5, 7, 9);//插入6for ($i=0; $i<count if count for> $j+1) ? $tmp2 = $arr[$j] : '';			$arr[$j] = $tmp1;			$tmp1 = $tmp2;		}		break;	}	}//输出print_r($arr);//Array ( [0] =&gt; 1 [1] =&gt; 3 [2] =&gt; 5 [3] =&gt; 6 [4] =&gt; 7 [5] =&gt; 9 ) ?&gt;</count>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

17 ways to solve the kernel_security_check_failure blue screen 17 ways to solve the kernel_security_check_failure blue screen Feb 12, 2024 pm 08:51 PM

17 ways to solve the kernel_security_check_failure blue screen

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Fix: Snipping tool not working in Windows 11

How to uninstall Skype for Business on Win10? How to completely uninstall Skype on your computer How to uninstall Skype for Business on Win10? How to completely uninstall Skype on your computer Feb 13, 2024 pm 12:30 PM

How to uninstall Skype for Business on Win10? How to completely uninstall Skype on your computer

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

Go language development essentials: 5 popular framework recommendations

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

How to Fix Can't Connect to App Store Error on iPhone

Implementing distributed task scheduling using Golang's web framework Echo framework Implementing distributed task scheduling using Golang's web framework Echo framework Jun 24, 2023 am 11:49 AM

Implementing distributed task scheduling using Golang's web framework Echo framework

See all articles