Skip to main content

Using php print pattern

This is not new concept, you need to follow same concept like C programming to print number pattern in php.

every time on interview ask question print pattern. this is important note please keep it.
Output :
Code :

<?php for($a=1; $a<=5; $a++)
{
 for($b=$a; $b>=1; $b--)
{
echo "$b";
}
echo "<br>";
} ?>

Now simple print one column then only one for loop use to print pattern 
This is not new concept, you need to follow same concept like C programming to print star pattern or triangle of star.
Output :
Code :
<?php for ($row = 1; $row <= 5; $row++)
{
 echo "* </br>";
} ?>

print * in square size as following manner and please follow following code :

Code :
<?php for ($row = 1; $row <= 5; $row++)
{
 for ($col = 1; $col <= 5; $col++)
  {
   echo '* ';
  }
   echo "</br>";
}
 ?>

PHP start pattern of trangle as output and code here :
Output :
Code :
<?php 
for($i=0;$i<=5;$i++)
{
for($j=1;$j<=$i;$j++)
{
echo "* ";
}
echo "<br>";
}
 ?>

as above example print pattern as mirror as follow :

Output :










Code :
<?php 

for($i=0;$i<=5;$i++)
{
for($j=5-$i;$j>=1;$j--)
{
echo "* ";
}
echo "<br>";
}
 ?>

New pattern of printing patter as following :
Output :
Code :
<?php 
for($a=5; $a>=1; $a--)
{
if($a%2 != 0)
{
for($b=5; $b>=$a; $b--)
{
echo "* ";
}
echo "<br>";
}
}
for($a=2; $a<=5; $a++)
{
 if($a%2 != 0)
{
 for($b=5; $b>=$a; $b--)
{
echo "* ";
}
echo "<br>";
}
}
 ?>

Following pattern of trangle print as refer following steps :
Output :

Code :
<?php 
for($i=0;$i<=9;$i++){

  for ($d=10-$i; $d > 0; $d--)  {

    echo    "&nbsp;&nbsp;";
  }
  for($j=1;$j<=$i;$j++){

    echo "&nbsp;".$i."&nbsp;";
 }

 echo "<br>";

} 
 ?>
please follow the following code to print pattern : 
Output :

Code :
<?php 
for($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo $i;
}
echo "<br>";
} 
 ?>
print one one at row and column as following :
Output :


Code :
<?php 
for($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo "1";
}
echo "<br>";
}
 ?>

HOW TO MAKE A NUMERIC POLYGON SHOWS ONLY ONE AND A PLUS SIGN WITH NUMBERS.

Output :


Code :
<?php 
$m=1; $n=9; $z=9;
for($i=1; $i<=$n; $i++){
 for($j=$i; $j<=$n-1; $j++){
   echo "&nbsp;&nbsp;&nbsp;";
   }
 for($k=1; $k<=$m; $k++){
  if($k==$m  || $k==1 || $i==$n){
     echo $k ."&nbsp";
     }
   else{
    echo "&nbsp;&nbsp;&nbsp;";
    }
  }
 for($c=$m; $c>1; $c--){
   if($c-1 == 1 || $m==$n){
     echo $c-1 ."&nbsp";
     }
   else{
     echo "&nbsp;&nbsp;&nbsp;";
     }
   }
   echo "<br>";
   $m++;
}
for($i=1; $i<=$n; $i++){
 for($j=1; $j<=$i; $j++){
   echo "&nbsp;&nbsp;&nbsp;";
   }
 for($k=1; $k<$z; $k++){
   if($k==1 || $k==$z-1){
     echo $k ."&nbsp";
     }
   else{
    echo "&nbsp;&nbsp;&nbsp;";
    }
  }
 for($c=$z-2; $c>=1; $c--){
   if($c==1){
     echo $c ."&nbsp";
     }
   else{
     echo "&nbsp;&nbsp;&nbsp;";
     }
  }
  echo "<br>";
  $z--;
}
 ?>

Make start polygon using php :
Output :

Code :
<?php 
 $m=1; $n=5;
for($i=1; $i<=5; $i++) {
    for($j=$i; $j<=4; $j++) {
        echo "&nbsp;&nbsp;";
    }
    for($k=1; $k<=$m; $k++)  {
        echo "*";
    }
    for($c=$m; $c>1; $c--) {
        echo "*";
    }
    echo "<br>";
    $m++;
}
 
for($i=1; $i<=5; $i++) {
    for($j=$i; $j>=1; $j--) {
        echo "&nbsp;&nbsp;";
    }
    for($k=$n; $k>1; $k--) {
        echo "*";
    }
    for($c=$n-1; $c>1; $c--) {
        echo "*";
    }
    echo "<br>";
    $n--;
} 
 ?>

I hope that my code and pattern you like and enjoy my code, if you like my code please share and comment,
thanks


Comments

Popular posts from this blog

Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links

Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links user want to share any information then use following code  and read step by step Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links if you want share profile on following social link : 1-Facebook 2-twitter.com 3-LinkedIn 4-google +, Code link : https://drive.google.com/open?id=1IzTZZh_0euDqFSHL_vPRiQePlNTw3h-q Demo link : http://freeteachnology.hol.es/socialshare/ To modify a page's thumbnail image, description, and additional metadata for these services, you can provide meta tags in the HTML code of the page.Implementing Open Graph Meta Tags You can implement meta tags in a number of ways. In content management systems might  be allow you to modify a page's meta tags , then use following code in meta section of your project code, <link href="bootstrap.min.css" rel="stylesheet"> <link href="bootstrap-tour.m...

FCM Notification in android and IOS App

Free Teachnology provide free #PHP,#MySql,#Javascript,#jQuery,#API integration,#Payment gateway integration,#Social Media login Firebase Cloud Messaging Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app IOS Setup link : https://firebase.google.com/docs/cloud-messaging/ios/client Andriod Link : https://firebase.google.com/docs/cloud-messaging/android/client Web Link : https://firebase.google.com/docs/cloud-messaging/js/client How does it work? Firebase Cloud Messaging architecture diagram An FCM implementation includes two main components for sending and receiving: A trusted environment such as Cloud Functions for Firebase ...