Echo Rules / Problems in PHP Language


0
Echo is used to show output results in PHP. But sometimes you get confuse for solving simple problems. like

How to add Conditional Statement within echo statement?

 It is wrong to use if conditional statement within echo statement. You should use ternary operator within echo statement. like
 echo '
  • ';
  • Can we use echo statement within echo statement?
    No we can not use echo statement within echo statement. It is bad logic.  

    Can we use echo with double or single quotes?
    Yes; you can use  echo with double and single quotes like

     echo 'This is Quality Written Codes Blog';  
    

    Output is : This is Quality Written Codes Blog

     echo "This is Quality Written Codes Blog";  
    

    Output is : This is Quality Written Codes Blog

    What is concatenation in echo statement? 
    Concatenation is sued to connect two quotes blocks. like  

     echo "My Blog Name is " . "Quality Written Codes";  
    


    ” . ” dot is used to add concatenation.


    How to use backslash within echo?
    There are two ways to use backslash within echo tag.

    You can use single quote if you want to use backslash; like it 

     echo 'This is Quality Written Codes Blog And My Name is  Samee Ullah Feroz ';  
    

    Its output is
    This is Quality Written Codes Blog and My Name is Samee Ullah Feroz

    If you use double quotes for echo statement. then you need to remember this solutions.

    1. / => /
    2. ” => “
    3. // => //
     echo "This is "Quality Written Codes" Blog and my name is \ Samee Ullah Feroz \";  
    

    Its output is 
    This is Quality Written Codes Blog and My Name is Samee Ullah Feroz

    How to use Variables within and with echo?
    You can use different methods for it. like  

     $blog = "Quality Written Codes";  
     echo "$blog";  
     echo '{$blog}'  
     echo $blog;