1 / 40

Setting the environment Overview of PHP Constants and Variables in PHP

Setting the environment Overview of PHP Constants and Variables in PHP. Operators in PHP Conditional Statements in PHP Looping Statements Arrays in PHP. Arithmetic Operators: +, - ,*, /, % Assignment Operators: = += ($a +=$b ), *= , /= .= ($a .= $b). Adds $b in $a.

megan-kerr
Download Presentation

Setting the environment Overview of PHP Constants and Variables in PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  2. Setting the environment • Overview of PHP • Constants and Variables in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  3. Operators in PHP • Conditional Statements in PHP • Looping Statements • Arrays in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  4. Arithmetic Operators: • +, - ,*, /, % • Assignment Operators: • = • += ($a +=$b ), *= , /= • .= ($a .= $b) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  5. Adds $b in $a Concatenates $b with $a Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  6. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  7. String Operators: • . , .= • $a=“abcd”.”efgh”; $a=abcdefgh • $a.=“ijk”; $a=abcdefghijk • Increment/decrement Operators: • ++,-- • $b=$a++ • $b=++$a Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  8. First variable Second variable Concatenation Using .= Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  9. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  10. Variable declared Incremented before display Incremented after display Displaying incremented value Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  11. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  12. Logical Operators: • AND, OR, NOT, XOR • &&, ||, ! • Equality Operators: • ==, !=, === • Comparison Operators: • >, <, <=, >= Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  13. Integer value String value Compares only values Strict comparison Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  14. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  15. if statement: if(condition) { } • if-else statement: if(condition) { } else { } Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  16. switch statement: switch(variable) { case option: action break; . . } Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  17. Switch starts case 0 Case 1 Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  18. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  19. for loop • while loop • do-while loop • foreach loop Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  20. for loop for($a=0; $a<10; $a++) { statements } • while loop while(condition) { Statements Increment/decrement } Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  21. do-while loop do { Statements Increment/decrement } While(condition) • foreach loop • is used to read an entire array Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  22. For loop While loop Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  23. Output from for loop Output from while loop Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  24. Array is declared Foreach loop starts Using obtained value Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  25. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  26. An array is traditionally defined as a group of items that share certain characteristics • Each item consists of two components: • the key and a value • PHP doesn’t require that you assign a size to an array at creation time • Declaring an array: • $array-name[key]=value Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  27. Declaring an array: • $array-name[key]=value • $players[0]=“Muhammad Yousuf”; • Adding element in an array: • $players[1]=“Younus Khan”; • Accessing element in an array • echo $players[0]; Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  28. Declaring array Adding elements Foreach loop Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  29. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  30. Associative arrays: • $array-name[‘element-name’]=value • $players[‘yousuf’]=“Muhammad Yousuf”; • Adding element in an array: • $players[‘younus’]=“Younus Khan”; • Accessing element in an array: • echo $players[‘yousuf’]; Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  31. The array();can also be used to create an array • $array_name=array(item_1,item_2,…item_n); • $players=array(“M.Yoursuf”,”Imran Khan”); • $players=array(“Yousuf”=>“M.Yoursuf”,”imran”=>”Imran Khan”); Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  32. Associative array is created using array() Accessing elements by name Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  33. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  34. Sorting arrays: • sort() • rsort() Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  35. Array is created Array is sorted Array is displayed Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  36. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  37. rsort() is used Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  38. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  39. Operators in PHP • Conditional statements • Looping statements • Arrays in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

  40. Chapter 2, “Beginning PHP6,Apache,Mysql web development” by Matt Doyle, Wrox publishers, 2009, ISBN: 0470413964 • Chapter 5, “Beginning PHP and MySQL” by W. Jason Gilmore, Apress publisher, 4th edition; 2010, ISBN-13 (electronic): 978-1-4302-3115-8. Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.

More Related