Advice needed in php program.

Discussion in 'PHP' started by pradipkeya, Jul 25, 2008.

  1. #1
    Sir ,
    I am a php learner i want to make a php program by which i can show star
    arrangement like this
    *****
    ****
    ***
    **
    *

    Any body can help me .

    Thank you
    pradip
     
    pradipkeya, Jul 25, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    $max = 5;
    $min = 1;
    
    
    for($x = $max;$x >= $min; $x--){
      
       for($y = $min;$y <= $x; $y++){
       
          echo ($y != $x)?' * ':' * <br>';
       
       }//end for 
    
    }//end for 
    PHP:
    Hope it's help. :)
     
    php-lover, Jul 25, 2008 IP
  3. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The following code also works perfectly:
    <?php
    for ( $counter = 5; $counter >= 1; $counter -= 1) {
    for($j=1; $j<=$counter; $j+=1)
    {
    echo "*";
    }
    ?>
    </br>
    <?php
    }
    ?>
     
    coder 525, Jul 25, 2008 IP
  4. pradipkeya

    pradipkeya Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sir,
    Thank you for helping me to understand the program. :)

    Pradip
     
    pradipkeya, Jul 25, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    
    $amount = 5;
    
    while ($amount)
    {
    	echo str_repeat('*', $amount--), "\n";	
    }
    
    PHP:
     
    nico_swd, Jul 25, 2008 IP
  6. pradipkeya

    pradipkeya Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6

    Thanks this is great idea you have supplied. I am really enjoying dp to learn php. Thanks a lot all of you for helping me a lot.
     
    pradipkeya, Jul 26, 2008 IP