Guest User

Untitled

a guest
May 30th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. ** PHP - Hypertext Preprocessor
  5. ** Server side scripting language
  6. ** Released Date : 1994
  7. ** Created By: Rasmus Lerdorf
  8. ** Most CMS used PHP -
  9. * WordPress
  10. * Joomla
  11. * Drupal
  12. ** Most popular website used PHP -
  13. * Facebook
  14. * Yahoo
  15. * Wikipedia
  16. * Flicker
  17. */
  18.  
  19.  
  20. ?>
  21.  
  22.  
  23. <?php
  24.  
  25. //variable
  26.  
  27. $myfriend = 'my friend name is jahed hossain';
  28. $br = '<br>';
  29.  
  30. echo $myfriend . $br;
  31.  
  32. /*
  33. Data types
  34. ====================
  35. 1. String - '', " " ;
  36. 2. Integer - 1,2,3....
  37. 3. Float - 1.1,1.2,1.3....
  38. 4. Bollean - true/false
  39. 5. Null -
  40. */
  41.  
  42. $name = 'Humayun ahmed'; //string
  43. $age = 21; //integer
  44. $result = 5.0; //float
  45.  
  46. echo $name . $br . $age . $br . $result . $br; //concatenation
  47.  
  48.  
  49. /*
  50. Operator
  51. =======================
  52. 1. Arithmetic Operator
  53. 2. Assignment Operator
  54. 3. Logical Operator
  55. 4. Comparison Operator
  56. 5. Array Operator
  57. 6. Increment/decrement Operator
  58. 7. String Operator
  59. */
  60.  
  61.  
  62.  
  63. /*
  64. 1. Arithmetic Operator
  65. =======================
  66. 1.1 - Plus : +
  67. 1.2 - Mynus : -
  68. 1.3 - Into : *
  69. 1.4 - Devided : /
  70. 1.5 - Modulas : %
  71. */
  72.  
  73. $father = 60;
  74. $son = 25;
  75.  
  76. $plus = $father + $son; //Plus
  77. $mynus = $father - $son; //Mynus
  78. $into = $father * $son; //Into
  79. $devided = $father / $son; //Devided
  80. $modulas = $father % $son; //Modulas
  81.  
  82. echo $plus . $br;
  83. echo $mynus . $br;
  84. echo $into . $br;
  85. echo $devided . $br;
  86. echo $modulas . $br;
  87.  
  88. /*
  89. 2. Assignment Operator
  90. =======================
  91. 2.1 - Plus-equal : +=
  92. 2.2 - Mynus-equal : -=
  93. 2.3 - Into-equal : *=
  94. 2.4 - Devided-equal : /=
  95. 2.5 - Modulas-equal : %=
  96. */
  97.  
  98. $age = 20;
  99. $age = $age += 5; //Plus-equal
  100. //$age = $age -= 5; //Mynus-equal
  101. //$age = $age *= 5; //Into-equal
  102. //$age = $age /= 5; //Devided-equal
  103. //$age = $age %= 5; //Modulas-equal
  104.  
  105.  
  106. echo $age . $br;
  107.  
  108.  
  109. /*
  110. 3. Logical Operator
  111. =======================
  112. 3.1 - (or) - ||
  113. 3.2 - (and) - &&
  114. 3.3 - (not) - !
  115. */
  116.  
  117. $username = 'humayunahmed8';
  118. $password = 'ha154248';
  119.  
  120.  
  121. // (and)
  122. if($username == 'humayunahmed8' && $password == 'ha154248'){
  123. echo 'login success' . $br;
  124. }else{
  125. echo 'login failed' . $br;
  126. }
  127.  
  128. //(or)
  129. /*
  130. if($username == 'humayunahmed8d' || $password == 'ha154248'){
  131. echo 'login success';
  132. }else{
  133. echo 'login failed';
  134. }
  135. */
  136.  
  137. /*
  138. 4. Comparison Operator
  139. =======================
  140. 4.1 - (equal) - ==
  141. 4.2 - (not equal) - !=
  142. 4.3 - (not equal) - <>
  143. 4.4 - (greater than) - >
  144. 4.5 - (greater than or equal to) - >=
  145. 4.6 - (less than) - <
  146. 4.7 - (less than or equal to) - <=
  147. */
  148.  
  149. $humayun = 20;
  150. $jahed = 18;
  151.  
  152. if($humayun > $jahed){
  153. echo 'true' . $br;
  154. }else{
  155. echo 'false' . $br;
  156. }
  157.  
  158.  
  159. $humayra = 17;
  160.  
  161. if($humayra >= 18){
  162. echo 'Ready for marriage' . $br;
  163. }else{
  164. echo 'not ready for marriage' . $br;
  165. }
  166.  
  167. /*
  168. 5. Array Operator
  169. =======================
  170. 5.1 - Indexed Array
  171. 5.2 - Associative Array
  172. 5.3 - Multidimensional Array
  173. */
  174.  
  175. // 5.1 - Indexed Array
  176.  
  177. $father = array(1=>'humayun','foysal','fariya');
  178.  
  179. //print_r($father);
  180.  
  181. echo $father[1] . $br;
  182.  
  183. // 5.2 - Associative Array
  184.  
  185. $mother = array('humayun'=>21,'foysal'=>18,'fariya'=>10);
  186.  
  187. //print_r($mother);
  188.  
  189. echo $mother['foysal'] . $br;
  190.  
  191.  
  192. // 5.3 - Multidimensional Array
  193.  
  194. $humayun = array(
  195. 'humayra' => array(
  196. 'class' => 12,
  197. 'group' => 'Business Studies',
  198. 'hobby' => 'Reading',
  199. ),
  200. 'abrar' => array(
  201. 'class' => 10,
  202. 'group' => 'Science',
  203. 'hobby' => 'Sleeping',
  204. ) ,
  205. 'jahanara' => array(
  206. 'class' => 9,
  207. 'group' => 'Humanities',
  208. 'hobby' => 'Singing',
  209. )
  210. );
  211.  
  212. //print_r($humayun);
  213.  
  214. //echo $humayun['humayra']['hobby'];
  215. //echo $humayun['abrar']['group'];
  216. //echo $humayun['jahanara']['class'];
  217.  
  218. echo $humayun['humayra']['hobby'].$br.$humayun['abrar']['group'].$br.$humayun['jahanara']['class'] . $br;
  219.  
  220.  
  221. /*
  222. Loop
  223. ==========
  224. 1. for loop
  225. 2. while loop
  226. 3. foreach loop
  227. */
  228.  
  229. //1. for loop
  230. //for(initialization,condition,increment/decrement);
  231.  
  232. for($i=100;$i>=1;$i--){
  233.  
  234. echo $i . $br;
  235.  
  236. }
  237.  
  238. //1++
  239. for($b=1;$b<=100;$b++){
  240. echo $b . $br;
  241. }
  242.  
  243. //2+2=4+2=6+2=8
  244. for($b=2;$b<=100;$b+=2){ // assign
  245. echo $b . $br;
  246. }
  247.  
  248. //1+2=3+2=5+2=7
  249. for($b=1;$b<=100;$b+=2){ // assign
  250. echo $b . $br;
  251. }
  252.  
  253. //2. while loop
  254.  
  255. $n=1;
  256.  
  257. while($n<=100){
  258. echo $n . $br;
  259. $n++;
  260. }
  261.  
  262. //3. foreach loop
  263.  
  264.  
  265. $rahman = array('ramim'=>20,'nadim'=>25,'hridoy'=>30,'sakib'=>28);
  266.  
  267. foreach($rahman as $child=>$year){
  268. //echo $child . $year . $br ;
  269. echo $child . ' age is' . $year . $br;
  270. }
  271.  
  272.  
  273. ?>
Add Comment
Please, Sign In to add comment