Your SlideShare is downloading. ×
02 Php Vars Op Control Etc
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

02 Php Vars Op Control Etc

848
views

Published on

Programming Basics in PHP

Programming Basics in PHP

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
848
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Assign $global and $GLOBALS
  • Transcript

    • 1. Day 2 PHP
      • Geshan Manandhar
      • Developer,
      • Young Innovations Pvt. Limited
      • www.geshanmanandhar.com
      http://www.php.net
    • 2. Variables in PHP
      • Boolean: It can be either TRUE or FALSE .
      • Integer: The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value.
      • Float: The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value
    • 3. Variable in PHP
      • String: A string is series of characters. In PHP, a character is the same as a byte, that is, there are exactly 256 different characters possible.
      • Array: An array in PHP is actually an ordered map. A map is a type that maps values to keys .
        • $names[1] = “Ram”;
        • $names[2] = “Shyam”;
    • 4. Variables in PHP
      • Objects: mainly have attributes and functions.
      • <?php
        • class test
        • {
        • function do_test()
        • {
        • echo &quot;Testing class function.&quot;;
        • }
        • }
        • $an_object = new test;
        • $an_object->do_test();
      • ?>
    • 5. Naming variables in PHP
      • Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.
      • A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
        • $a_5=10; //valid
        • $#b = 20; //invalid
      • Predefined Variables ($_SERVER, $_POST)
    • 6. Constant
      • You can define a constant by using the define() -function. Once a constant is defined, it can never be changed or undefined.
      • <?php
      • define(&quot;PI&quot;, 3.1415); //defining a constant called PI
      • $r=5; //r for radius
      • $area = PI*$r*$r; //area calculation of circle
      • print &quot;Areas of circle with radius $r is &quot;.$area.&quot;.&quot;;
      • //user number_format() yourself.
      • ?>
    • 7. Arithmetic Operators See Program for more clarification: Day02prog06_Operators.php
    • 8. Comparison Operators See code of Day02prog08_comparision_operators.php
    • 9. Increment Decrement Operators
      • ++ and --
      Code at Day02prog09_inc_dec_operator.php
    • 10. Logical Operator
    • 11. String Operator
      • . used to concatenate strings
      • .= used to append a string.
      • <?php $b = ”Hello” . &quot;World!&quot;; // now $b contains &quot;Hello World!&quot; $a = &quot;Hello &quot;; $a .= &quot;World!&quot;;  // now $a contains &quot;Hello World!&quot; ?>
    • 12. If-else if- else
      • <?php
      • $a=10;
      • $b=17;
      • if ($a > $b) {
      • echo &quot;a is bigger than b&quot;;
      • } elseif ($a == $b) {
      • echo &quot;a is equal to b&quot;;
      • } else {
      • echo &quot;a is smaller than b&quot;;
      • }
      • ?>
    • 13. If-else if- else alternate
      • <?php
      • $a=10;
      • $b=17;
      • if ($a > $b) :
      • echo &quot;a is bigger than b&quot;;
      • elseif ($a == $b) :
      • echo &quot;a is equal to b&quot;;
      • else :
      • echo &quot;a is smaller than b&quot;;
      • endif;
      • ?>
    • 14. Switch Example
      • <?php
      • $engDay =date (&quot;l&quot;);
      • switch ($engDay)
      • {
      • case &quot;Friday&quot;;
      • print &quot;Thank god its Friday&quot;;
      • break;
      • case &quot;Saturday&quot;;
      • print &quot;Oh its week end Saturday&quot;;
      • break;
      • default:
      • print &quot;Its just another working day of the week.&quot;;
      • }
      • ?>
    • 15. While Loop
      • <?php
      • $i = 1;
      • while ($i <= 10) {
      • echo $i++;
      • }
      • /* example 2 Alternative syntax*/
      • $i = 1;
      • while ($i <= 10):
      • echo $i;
      • $i++;
      • endwhile;
      • ?>
    • 16. Do While Loop
      • <?php $i = 0; do {     echo $i; } while ($i > 0); ?>
    • 17. For Loop
      • <?php
      • for ($i = 1; $i <= 10; $i++) {
      • echo $i;
      • }
      • /*Alternate for Syntax */
      • for($i = 0; $i <= 10; $i++):
      • echo &quot;--&quot;.$i;
      • endfor;
      • ?>
    • 18. For Each loop
      • <?php
      • $arr = array(&quot;zero&quot; , &quot;one&quot; , &quot;two&quot; , &quot;three&quot; , &quot;four&quot; );
      • /*For each example 1 */
      • foreach ( $arr as $value ){
      • print &quot;<br>&quot;.$value;
      • }
      • print &quot;<br>&quot;;
      • /*For each example 2 */
      • foreach ( $arr as $key => $value) {
      • print &quot;<br>At key &quot;.$key.&quot; of the array, the value is &quot;.$value;
      • }
      • ?>
    • 19. PHP simple Function
      • <?php
      • function adder($var1, $var2){
      • $sum = $var1+$var2;
      • return $sum;
      • }
      • ?>
      • <html>
      • <head>
      • <title>Function with PHP an example</title>
      • </head>
      • <body>
      • <?php
      • $a=10;
      • $b=15;
      • $added = adder($a, $b);
      • ?>
      • The sum of <?=$a?> and <?=$b?> is <?=$added?>.
      • </body>
      • </html>
    • 20. Lets get rolling
      • Write a program that performs all arithmetic operations with 3 variables.
      • Get the month with date(“F”) function and if its December and day date(“d”) is greater than 20 and less than 26, print “Merry Christmas”.
      • Print multiplication table of 5 with for loop.
      • Use foreach loop for an array called names and print the names in the array with its keys.
    • 21. Questions are welcome
      • That’s why god gave us two eyes, two ears but only one mouth.