Basic knowledge of PHP language

  •  PHP Code :- For Partiality and Compatibility always use the long form.
          Long farm :         <?php    Expn     ?>
          Sort form  :         <?          Expn      ?>
         Sort form equivalent of <?    echo    ?>
         Note : No closing semicolon (;) is required <?     Expn      ?>

  • Semicolon (;) :- All statement must end in a semicolon (;) otherwise, errors will be generated. If the error doesn't make sense. You probably are missing a semicolon somewhere !
  • Single Quotations ('') :-  Single quotes content inside single quotes is evaluated literally.Therefore $ string actually means ( dollar sing ) string and does not represent the variables.
Example:
$string = ' single quoted ';
echo '$string';


  • Double Quotes ("") :- Double Quoted variable inside double quotes are evaluated for their value.
Example: 
$string=" double quoted ";
echo "$string";

  • Backslash ( Escape character ):- Escapes character that sold be evaluated literally when inside inside double quotation.
Example:  
$string= "double quoted";
echo "\$string is set as $string";
$string is set as double quotes.

  • Special characters :-  
Backslash (\)
Question mark (?)
Single Quotes (')
Double Quotes (")
Doller sing ($)

  • Comments :-  Single line for everything to the right of the double forward slashes.
// This is a comments.
Multiple line opening and closing tags.
/*        This is a comment      */  


  • Formatting Character :-
\n - New Line
\r - Carriage return
\t - Tab
\b - Back space


  • Define (name, value [$Boolean]):-
$Boolean - [optional] default: false, case-sensitive define a Constance a set value that is assigned globally making it variable to function and an argument.
Example:    
define('Hello', 'Hello word!' );
echo Hello;
Output: Hello word!

  • Function:- Function function name(argument) {},
function can be places only where in a page and will be available even with called above the actual function  being created as part of conditional statement has been evaluated.
Example: 
hello();
// Above the conditional statement this will cause an error 
if(0==0)
{
function hello()
{
echo 'Hello';
}
}

Fatal error: call to undefined function hell()
if(0==0)
{
function hello()
{
echo 'Hello ';
}
}

hello();
there();

function there()
{
echo 'there';
}


Hello there: function can have a argument (as above), argument passed to them, an default arguments with passed argument as optional. The argument names are use within that function as variable name.
Example:
function args($a,$b)
{
// has no default values request to input
echo "a=$a, b=$b";
}
args(1,2);
Output:
a=1,b=2


No comments:

Post a Comment

Python in AI: Getting Started with TensorFlow & PyTorch

  Artificial Intelligence (AI) is no longer just a buzzword. It powers recommendation systems, chatbots, self-driving cars, and more. At the...