Q:

Alphabet Triangle Pattern in Php

belongs to collection: PHP Programs

0

Some different alphabet triangle patterns using range() function in PHP are shown below.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Pattern 1

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
  for($j=5; $j>$i; $j--){  
    echo $alpha[$i];  
    }  
    echo "<br>";  
}  
?>  

Output:

 

Pattern 2

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
  for($j=0; $j<=$i; $j++){  
    echo $alpha[$i];  
    }  
    echo "<br>";  
}  
?>  

Output:

 

Pattern 3

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
  for($j=0; $j<=$i; $j++){  
    echo $alpha[$j];  
    }  
    echo "<br>";  
}  
?>  

Output:

 

Pattern 4

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
  for($j=4; $j>=$i; $j--){  
    echo $alpha[$j];  
    }  
    echo "<br>";  
}  
?>  

Output:

 

Pattern 5

<?php  
$alpha = range('A', 'Z');  
for ($i=5; $i>=1; $i--) {    
  for($j=0; $j<=$i; $j++) {    
     echo ' ';    
  }  
  $j--;  
for ($k=0; $k<=(5-$j); $k++) {    
    echo $alpha[$k];   
}    
echo "<br>\n";  
}  
?>  

Output:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Number Triangle in Php... >>
<< Alphabet Triangle Method in Php...