Home >Backend Development >PHP Tutorial >How to output an isosceles triangle in PHP, PHP outputs an isosceles triangle_PHP tutorial

How to output an isosceles triangle in PHP, PHP outputs an isosceles triangle_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:54:152354browse

How to output an isosceles triangle in PHP, and how to output an isosceles triangle in php

The example in this article describes how to output an isosceles triangle in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

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);

The running results are as follows:

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

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/998559.htmlTechArticleHow to output an isosceles triangle in PHP, how to output an isosceles triangle in php. This article explains how to output an isosceles triangle in PHP. method. Share it with everyone for your reference. The specific implementation methods are as follows...
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