Home >Backend Development >PHP Tutorial >PHP输出一个等腰三角形的方法_PHP

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

WBOY
WBOYOriginal
2016-06-01 14:35:291280browse

本文实例讲述了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);

运行结果如下:

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

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

Statement:
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