How to get following output using PHP

Lemon Kazi

My sample desired output should be

1 2 3 4 5
2       4
3       3
4       2
5 4 3 2 1

Here is my PHP code

for($i=1;$i <= 5;$i++) {
    for($j=1;$j<=$i;$j++) {
      echo "$j";
    }
    for($y=0;$y<(5-$i)*4;$y++) {
      echo '&nbsp;';
    }
    for($l=$i;$l>0;$l--) {
      echo "$l";
    }
    echo "<br/>";
}

But I got this output.

output:-

1        1
12      21
123    321
1234  4321
1234554321

Please try to solve my problem. Thanks in advance.

lafor

Here's a quick solution for an arbitrary array of 1-character values:

$values = range(1,7);
$count = count($values);
foreach($values as $k=>$v) {
   if($k == 0)
      echo implode(" ", $values), "\n";
   elseif($k == $count-1)
      echo implode(" ", array_reverse($values)), "\n";
   else
      echo $v, " ", str_repeat("  ", $count-2), $values[$count-1-$k], "\n";
}

This will produce:

1 2 3 4 5 6 7
2           6
3           5
4           4
5           3
6           2
7 6 5 4 3 2 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the output for the following?

From Dev

How can i get the following output using linux sorting?

From Dev

How to get the output for the following code?

From Dev

I want the following output using for loop in php

From Dev

how to get the output in array using echo php

From Dev

How to use Sed command to get following output?

From Dev

How to get output, when using fsockopen to open a php page?

From Dev

How to get output, when using fsockopen to open a php page?

From Dev

how to get the following fields using Joins?

From Dev

How to extract following xml using PHP

From Dev

How is the following output generated?

From Dev

How to print in following output

From Dev

What is the output of the following PHP code?

From Dev

What is the output of the following PHP code?

From Dev

How to get this output using JOIN

From Dev

How to get json output in php from url and get specific result using foreach

From Dev

get the output of array in deciending order using php

From Dev

How to write the reg express to get the following pattern in the php?

From Dev

How to output all the elements in an array in the following output?

From Dev

How to get the following dictionary?

From Dev

How to split and concatenate the string to get the following result using jquery

From Dev

How to get a text from following div using Selenium Webdriver

From Dev

How can i get the following results using MySQL

From Dev

How to get anything following the domain in a url, using Javascript

From Dev

How to split and concatenate the string to get the following result using jquery

From Dev

How to get Instagram following list using http component in Delphi 10

From Dev

How to implement autocomplete functionality using PHP, jQuery and AJAX in following scenario?

From Dev

How to print following json data using foreach in php

From Dev

I want to get following output by using procedure or query anything in sql server

Related Related

  1. 1

    How to get the output for the following?

  2. 2

    How can i get the following output using linux sorting?

  3. 3

    How to get the output for the following code?

  4. 4

    I want the following output using for loop in php

  5. 5

    how to get the output in array using echo php

  6. 6

    How to use Sed command to get following output?

  7. 7

    How to get output, when using fsockopen to open a php page?

  8. 8

    How to get output, when using fsockopen to open a php page?

  9. 9

    how to get the following fields using Joins?

  10. 10

    How to extract following xml using PHP

  11. 11

    How is the following output generated?

  12. 12

    How to print in following output

  13. 13

    What is the output of the following PHP code?

  14. 14

    What is the output of the following PHP code?

  15. 15

    How to get this output using JOIN

  16. 16

    How to get json output in php from url and get specific result using foreach

  17. 17

    get the output of array in deciending order using php

  18. 18

    How to write the reg express to get the following pattern in the php?

  19. 19

    How to output all the elements in an array in the following output?

  20. 20

    How to get the following dictionary?

  21. 21

    How to split and concatenate the string to get the following result using jquery

  22. 22

    How to get a text from following div using Selenium Webdriver

  23. 23

    How can i get the following results using MySQL

  24. 24

    How to get anything following the domain in a url, using Javascript

  25. 25

    How to split and concatenate the string to get the following result using jquery

  26. 26

    How to get Instagram following list using http component in Delphi 10

  27. 27

    How to implement autocomplete functionality using PHP, jQuery and AJAX in following scenario?

  28. 28

    How to print following json data using foreach in php

  29. 29

    I want to get following output by using procedure or query anything in sql server

HotTag

Archive