Home > php教程 > php手册 > PHP输出一个等腰三角形的方法,php输出等腰三角形

PHP输出一个等腰三角形的方法,php输出等腰三角形

WBOY
Release: 2016-06-13 09:04:45
Original
4422 people have browsed it

PHP输出一个等腰三角形的方法,php输出等腰三角形

本文实例讲述了PHP输出一个等腰三角形的方法。分享给大家供大家参考。具体实现方法如下:

function isosceles($line,$sing){
  $tab ='=';  
  for($i=1;$i < $line+1;$i++){
    $blank = print_blank($i,$line,$tab);
    $code = print_code($i,$sing);
    echo $blank.$code.$blank."<br>";
  }
}
function print_blank($num,$line,$tab){
  $blank ='';
  for($i=$num;$i<$line;$i++){
    $blank.=$tab;
  }
  return $blank;
}
function print_code($num,$sing){
  $code ='';
  for($i=0;$i<(2*($num-1)+1);$i++){
    $code.=$sing;
  }
  return $code;
}
$line = 5;
$sing = "*";
isosceles($line,$sing);
Copy after login

运行结果如下:

====*====
===***===
==*****==
=*******=
*********

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template