Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 50

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

  1. #11
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I didn't get the correct answer. http://php.flashwebhost.com/sherly/variable.php

    Code:
    <?php
    
    $variable12 = $variable7 + $variable5;
    echo $variable7;
    echo " + ";
    echo $variable5;
    echo " = ";
    echo $variable12;

  2. #12
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/age.php

    Code:
    <?php
    
    $name = 'Joseph';
    $yearBorn = 1975;
    $currentYear = 2014;
    $age = $currentYear - $yearBorn;
    
    print ("$name is $age years old. ")

  3. #13
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sherlyk View Post
    http://php.flashwebhost.com/sherly/age.php

    Code:
    <?php
    
    $name = 'Joseph';
    $yearBorn = 1975;
    $currentYear = 2014;
    $age = $currentYear - $yearBorn;
    
    print ("$name is $age years old. ")
    Semicolon at end of print statement missing.

    print function same as echo, but use echo, forget print. echo is more popular, also there are more ways to print, some complicated, but is not required for most programming project.

    Code:
    print ("$name is $age years old. ")
    Proper usage

    Code:
    echo $name . ' is ' .  $age . ' years old. ';
    Or

    Code:
    echo "$name  is  $age years old. ";
    Advantage of using single quote is PHP know it is just string, so it will be faster. If using double quote, PHP compilter need to look for variable inside the string and convert it to its value, that need more processing time (not much, still do that way as a convention whenever possible).
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

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

    Default

    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 ?

  5. #15
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PHP PROGRAMMING

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

    Code:
    <?php
    
    
    $MovieName = '<b>Mr. Fraud</b>';
    
    
    echo $MovieName ;

  6. #16
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PROGRAMMING

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

    Code:
    <?php
    
    
    $MovieName = '<b>Mr. Fraud</b>';
    
    
    echo 'Mohanlal\'s Upcoming Movie '  .  $MovieName;

  7. #17
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PROGRAMMING

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

    Code:
    <?php
    
    
    $MovieName = 'Mr. Fraud' ;
    $Starring = 'Mohanlal, Siddique, Dev Gill, Pallavi, Mia, Manjari' ;
    $Director = 'B. Unnikrishnan' ;
    
    
    echo $MovieName . ' is a malayalam movie, ' . $Director . ' is the Director. ' . $Starring . ' in the lead roles. ' ;

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

    Default String and numeric variables example - day_2_variables_3

    Code:
    <?php
    $brand = 'Sony Xperia J';
    $product = 'Mobile';
    $android = 'Jelly Bean 4.3';
    $shop = 'Flipkart';
    
    
    echo ' Purchased ' .  $brand . $product . ' from ' . $shop . ' . Android version is ' . $android;
    Created code like above.

    Result below

    Purchased Sony Xperia JMobile from Flipkart . Android version is Jelly Bean 4.3


    there is no gap between xperia j and Mobile.

    So i just added the . ' ' . to get space.

    echo ' Purchased ' . $brand . ' ' . $product . ' from ' . $shop . ' . Android version is ' . $android;



    2 doubts


    1. Is there any issue if two variables come together ? ($brand . ' ' . $product .)

    2. any problem if we use quote ,when we have text and numeric values ($android = 'Jelly Bean 4.3';). I just tried by removing the quote. but showing error message.
    Last edited by Vahaa11; 05-09-2014 at 10:30 AM.

  9. #19
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PROGRAMMING

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

    Code:
    <?php
    
    
    $MovieName = 'Mr. Fraud' ;
    $Starring = 'Mohanlal, Siddique, Dev Gill, Pallavi, Mia, Manjari' ;
    $writtenDirector = 'B. Unnikrishnan' ;
    $Banner = 'A.V.A Productions' ;
    $Producer = 'A. V. Anoop' ;
    $Cinematography = 'Satheesh Kurup' ;
    $Music = 'Gopi Sunder' ;
    $lyrics = 'Hari Narayanan & Chittoor Gopi' ;
    $editing = 'Manoj' ;
    $stuntchoreography = 'Stunt Silva' ;
    $ReleaseDate = 'May 17' ;
    
    
    echo $MovieName . ' is a Malayalam heist film written and directed by ' . $writtenDirector . ' and starring ' . $Starring . 'in the lead roles. The film is produced by ' . $Producer . ' under the banner ' . $Banner ; echo '.' ;
    
    
    echo ' The film\'s music composed by ' . $Music . ', with lyrics penned by ' . $lyrics . ' Cinematography is handled by ' . $Cinematography . ', editing is by ' . $editing . ' and stunt choreography is by ' . $stuntchoreography ; echo '.' ;
    
    
    echo ' The shooting has been completed on April first week and already two teasers are out. The trailer and songs are commenced to release on April 25. The movie is decided to release on ' . $ReleaseDate ; echo '.' ;

  10. #20
    Join Date
    Jan 2008
    Location
    india,kerala-god's own country
    Posts
    14,007

    Default

    DAY 2 PROGRAMMING - My Post

    http://php.flashwebhost.com/ramesh/study2.php


    Code:
    <?php
    
    $film = 'Gangster';
    
    echo  'Film: ' . $film; echo '. <br>';
    
    $actor = 'Mammootty';
    
    echo  'Actor: ' . $actor; echo '. <br>';
    
    $actress = 'Nyla Usha';
    
    echo  'Actress: ' . $actress; echo '. <br>';
    
    $director = 'Aashiq Abu';
    
    echo  'Director: ' . $director; echo '.';

Page 2 of 5 FirstFirst 1234 ... 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
  •