Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 50

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

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

    Default

    DAY 2 PROGRAMMING. EXAMPLE 5

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

    MY CODE IS:
    Code:
    <?php
    
    
    $numberOfWorkers = 5;
    $wagePerWorker = 650;
    
    
    echo '<p>' . 'Total Number of workers ' . '= ' . $numberOfWorkers . '</p>';
    
    
    echo '<p>' . 'Wage per worker ' . '= '. $wagePerWorker . '</p>';
    
    
    echo '<p>' . 'Total wage for all workers will be ' . '= ' . ($numberOfWorkers * $wagePerWorker) . '/-' . "</p>";

  2. #32
    Join Date
    May 2014
    Posts
    21

    Arrow suggestions

    Quote Originally Posted by vineesh View Post
    http://php.flashwebhost.com/vineesh/...ariables_2.php

    I was facing difficulty to insert a full stop after a sentence. But I managed to make it work. My code is

    Code:
    <?php
    
    $staffName = 'Ramesh';
    $companyName = 'HOSTONNET';
    
    $staffName2 = 'Suresh';
    
    $staffName3 = 'Tom';
    
    echo $staffName . ' is working in ' . $companyName;  echo '.'; echo ' But '; echo $staffName2; echo ' not.' ;
    
    echo '<br>';
    
    echo $staffName3 . ' also working in ' . $companyName . 'for the past 10 years'; echo '.';
    Is there any issue with this ?
    your code is working and error free. I also got a suggestion that it could be reduced too.
    i have modified your code in here:
    Code:
    <?php
    
    
    $staffName = 'Ramesh';
    $companyName = 'HOSTONNET';
    
    
    $staffName2 = 'Suresh';
    
    
    $staffName3 = 'Tom';
    
    
    echo $staffName . ' is working in ' . $companyName.'. But '.$staffName2.' is not.<br>'.$staffName3.' also working in '.$companyName .' for the past 10 years.';
    you could do everything in one echo. lesser code faster work ;)

  3. #33
    Join Date
    May 2014
    Posts
    21

    Post 1 doubt

    PHP Code:
    <?php

    $name
    'crazyfrog';
    $action ' is coming to town.';
    $n1 8;
    $n2=9;

    echo 
    $name.$action;
    echo 
    '<br>';
    echo 
    '8 + 9 = ' . ($n1+$n2);
    echo 
    '<br>' . (8*9);
    1 doubt

    does php use any preference rules from maths?
    like BODMAS (Bracket, of, division, multiplication, addition, subtraction) rule or something?
    when echoed does the compiler compiles the things in bracket first?

    i had an error when i omitted the bracket of 8*9
    PHP Code:
    echo '<br>'.(8*9); 
    had error with this code.
    PHP Code:
    echo '<br>'.8*9
    Last edited by Austinwhite; 05-09-2014 at 12:18 PM. Reason: spellling error

  4. #34
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    @Austinwhite Please don't ask too much complicated maths questions. No one here understand BODMAS or preference rules from maths

    PHP Code:
    echo '<br>'.8*9
    I think PHP is confused about that to do here. So it is better use brackets when you use maths operation.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  5. #35
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default Same variable name for multiple values

    Quote Originally Posted by annie View Post
    I got an error while adding break in http://php.flashwebhost.com/annie/company.php

    Code:
    Parse error:  syntax error, unexpected '>' in /home/fwhphp/public_html/annie/company.php on line 3 
    Code:
     <?php
    $companyname = 'Relience';
    echo $companyname <br> ; 
    $companyname = 'Whirpool'; 
    echo $companyname ;
    Doubt 1
    Is it possible to use same variable name for multiple values ?

    Doubt 2
    Is variable name is case sensitive ?

    I mean both the following variables will give different values in the same script ?

    $variableName
    $variablename
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  6. #36
    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.

  7. #37
    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)) . '/-' ;

  8. #38
    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 )) . '/-' ;

  9. #39
    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.

  10. #40
    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 ) ) . '/-';

Page 4 of 5 FirstFirst ... 2345 LastLast

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
  •