Results 1 to 10 of 50

Thread: Day 2 - Variables - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by melbin View Post
    Doubt 1
    Is it possible to use same variable name for multiple values ?
    Variables can store only 1 value at a time. If you store new value to a variable, value of variable changes to that new value.

    Quote Originally Posted by melbin View Post
    Doubt 2
    Is variable name is case sensitive ?

    I mean both the following variables will give different values in the same script ?
    Variables are case sensitive.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  2. #2
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_2_variables_6.php

    Code:
    <?php
    
    
    $computerPrice = '20000' ;
    $printerPrice = '5000' ;
    $discount = 0.1; // 10% discount.
    
    
    echo ' Total cost = Rs: ' . ($computerPrice+$printerPrice) . ' /- ' ;
    echo '<br>' ; 
    echo ' Price after discount = Rs: ' . ( ($computerPrice + $printerPrice) -  (($computerPrice + $printerPrice) *  $discount)) . '/-' ;

  3. #3
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_2_variables_7.php

    Code:
    <?php
    
    
    $computerPrice = 20000 ;
    $printerPrice = 5000 ;
    $discount = 0.2 ; // 20% discount.
    $totalCost = $computerPrice + $printerPrice ;
    
    
    echo ' Total cost = Rs: ' . $totalCost . '/-' ;
    
    
    echo '<br>' ;
    
    
    echo ' Price after discount = Rs. ' . ($totalCost - ($totalCost * $discount )) . '/-' ;

  4. #4
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default

    I just tried with $discount = 0.1 , $discount = 0.2.

    But when i add $discount = 12 , the result was wrong.

    So i searched in google for "percentage formula in php" and i got the following


    PHP Code:
    <?php$shirt_price = 300;$pant_price = 300;$discount = 12;$total_cost = ($shirt_price+$pant_price);
    echo 'Total price is Rs :  ' . $total_cost . '/-';
    echo '<br>';
    echo ' Price after discount is Rs : ' . ($total_cost - ($total_cost*$discount / 100)). '/-';
    See the result at http://php.flashwebhost.com/sibichan...ariables_7.php
    Last edited by Vahaa11; 05-10-2014 at 05:46 AM.

  5. #5
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    DAY 2 PROGRAMMING:

    http://php.flashwebhost.com/vineesh/...ariables_6.php

    Seems it worked :). My code is:

    Code:
    <?php
    
    
    $costOfApple = 50;
    $costOfOrange = 30;
    $discount = 0.5; // 50% discount.
    
    
    echo 'Cost of an apple = ' . $costOfApple . '<br>' . 'Cost of Orange = ' . $costOfOrange . '<br>';
    echo 'Cost of apple + Orange = ' . ($costOfApple + $costOfOrange) . '<br>';
    echo 'Discount ' . $discount . '<br>' ;
    echo 'Cost after discount = ' . ( ($costOfApple + $costOfOrange) - (($costOfApple + $costOfOrange) * $discount ) ) . '/-';

  6. #6
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    DAY 2 PROGRAMMING .

    http://php.flashwebhost.com/vineesh/...ariables_7.php

    Code
    Code:
    <?php
    
    $costOfApple = 100;
    $costOfOrange = 70;
    $totalCost = $costOfApple + $costOfOrange;
    $discount = 0.2;
    
    
    echo 'Cost of Apple = Rs. ' . $costOfApple . ' /- <br>';
    echo 'Cost of Orange = Rs. ' . $costOfOrange . '/- <br>';
    echo 'Total Cost = Rs. ' . $totalCost . '/- <br>';
    echo 'Discount = Rs. ' . $totalCost * $discount . '/-  <br>' ;
    echo 'Cost after discount = Rs. ' . ( ( $totalCost ) - ( ($totalCost) * $discount )) . '/- <br>';

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •