Advertisement
Guest User

Class-1 PHP Practis

a guest
May 13th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. <?php
  2.  
  3. // Variable, string, integer, float.
  4. echo'<h3> Variable, string, integer, float. </h3>';
  5.  
  6. $Name = 'Md. Anwar Hossen';
  7. $age = 34;
  8. $balance =1.5;
  9. $br = '<br>';
  10.  
  11. echo $Name .$br. $age .$br. $balance;
  12.  
  13.  
  14.  
  15. // Using Arithmetic Operator
  16. echo'<h1> Using Arithmetic Operator. </h1>';
  17.  
  18.  
  19. $apple = 102;
  20. $orange = 34;
  21.  
  22. $addition = $apple + $orange;
  23. $subtraction = $apple - $orange;
  24. $multiplication = $apple * $orange;
  25. $division = $apple/$orange;
  26. $modulus = $apple%$orange;
  27.  
  28.  
  29. echo'<h3> 1. Addition 102 & 34. </h3>';
  30. echo $addition.'</br>';
  31.  
  32. echo'<h3> 2. Subtraction 102 & 34. </h3>';
  33. echo $subtraction.'</br>';
  34.  
  35. echo'<h3> 3. Multiplacation 102 & 34. </h3>';
  36. echo $multiplication.'</br>';
  37.  
  38. echo'<h3> 4. Division 102 & 34. </h3>';
  39. echo $division.'</br>';
  40.  
  41. echo'<h3> 5. Modulus 102 & 34. </h3>';
  42. echo $modulus.'</br>';
  43.  
  44.  
  45.  
  46. // Using Assignment Operator
  47. echo'<h1> Using Assignment Operator (=, +=, -=, *=, /=). </h1>';
  48.  
  49. $age = 30;
  50.  
  51. echo'<h3> 1. Adding age 5 year with previous age 30. </h3>';
  52. echo $age += 5; echo '</br>';
  53.  
  54. echo'<h3> 2. Subtraction age 5 year from previous age 35. </h3>';
  55. echo $age -= 5; echo '</br>';
  56.  
  57. echo'<h3> 3. Multiplication age 5 year from previous age 30. </h3>';
  58. echo $age *= 5; echo '</br>';
  59.  
  60. echo'<h3> 4. Division age with 5 year to previous age 150. </h3>';
  61. echo $age /= 5; echo '</br>';
  62.  
  63.  
  64.  
  65. // Logical Operator
  66. echo'<h1> Logical Operator ( ||, &&, !). </h1>';
  67.  
  68.  
  69. $username = 'anwar';
  70. $password = 'anwar123';
  71.  
  72. if($username == 'anwar' && $password == 'anwar12' ){
  73. echo '<h2>Welcome to our website </h2>';
  74. }
  75.  
  76. else{
  77. echo '<h2> User name or password wrong</h2>';
  78. }
  79.  
  80.  
  81.  
  82. // Comparison Operator
  83. echo'<h1> Comparison Operator ( ==, !=, <, >, <=, >=, <>). </h1>';
  84.  
  85.  
  86.  
  87.  
  88. $Nazrul = 70;
  89. $Rabindra = 105;
  90.  
  91. //one
  92. if($Nazrul == $Rabindra ){
  93. echo '<h2>There age is equel</h2>';
  94. }
  95.  
  96. else{
  97. echo '<h2> There age is not equel</h2>';
  98. }
  99.  
  100.  
  101. //two
  102. if($Nazrul > $Rabindra ){
  103. echo '<h2>Nazrul is elder then Rabindra</h2>';
  104. }
  105.  
  106. else{
  107. echo '<h2> Nazrul is younger then Rabindra</h2>';
  108. }
  109.  
  110.  
  111. // three
  112. if($Nazrul != $Rabindra ){
  113. echo '<h2>There age is not equel</h2>';
  114. }
  115.  
  116. else{
  117. echo '<h2> There age is equel</h2>';
  118. }
  119.  
  120.  
  121. // Index Array
  122. echo'<h1> Index Array </h1>';
  123.  
  124.  
  125. $subject = array('English', 'Math', 'Bangla', 'Biology',);
  126.  
  127. print_r ($subject);
  128.  
  129. echo '</br>'. '</br>';
  130.  
  131. echo $subject[0] .'</br>'. '</br>';
  132. echo $subject[1] .'</br>'. '</br>';
  133. echo $subject[2] .'</br>'. '</br>';
  134. echo $subject[3] .'</br>'. '</br>';
  135.  
  136.  
  137. // Associative Array
  138. echo'<h1> Associative Array </h1>';
  139.  
  140.  
  141. $student = array('Rahim'=>15, 'Karim'=>17, 'Jabbar'=>18, 'Barkat'=>21,);
  142.  
  143. print_r ($student);
  144.  
  145. echo '</br>'. '</br>';
  146.  
  147. echo 'The age of Rahim is = '. $student['Rahim']. ' years' .'</br>'. '</br>';
  148. echo 'The age of Karim is = '. $student['Karim']. ' years' .'</br>'. '</br>';
  149. echo 'The age of Jabbar is = '. $student['Jabbar']. ' years' .'</br>'. '</br>';
  150. echo 'The age of Barkat is = '. $student['Barkat']. ' years' .'</br>'. '</br>';
  151.  
  152.  
  153.  
  154.  
  155. // Multidimentional Array
  156. echo'<h1> Multidimentional Array </h1>';
  157.  
  158.  
  159. $student = array(
  160. 'Rahim'=>array(
  161. 'roll'=>1,
  162. 'group'=>'Science',
  163. 'age'=>20,
  164. ),
  165.  
  166. 'Karim'=>array(
  167. 'roll'=>2,
  168. 'group'=>'Arts',
  169. 'age'=>21,
  170. ),
  171.  
  172. 'Jabbar'=>array(
  173. 'roll'=>3,
  174. 'group'=>'Commerce',
  175. 'age'=>22,
  176. ),
  177.  
  178. );
  179.  
  180. echo '<pre>';
  181. print_r ($student);
  182.  
  183. echo '</br>'. '</br>';
  184.  
  185. // ==========Rahim Details=====================
  186. echo '<h3>Name of Student : Rahim</h3> ';
  187.  
  188. echo '<ol>';
  189. echo '<li>Roll : '. $student['Rahim']['roll']. '</li>';
  190. echo '<li>Group : '. $student['Rahim']['group']. '</li>';
  191. echo '<li>Age : '. $student['Rahim']['age']. '</li>';
  192. echo '</ol>';
  193.  
  194.  
  195.  
  196. // ==============Karim Details==============
  197. echo '<h3>Name of Student : Karim</h3> ';
  198.  
  199. echo '<ol>';
  200. echo '<li>Roll : '. $student['Karim']['roll']. '</li>';
  201. echo '<li>Group : '. $student['Karim']['group']. '</li>';
  202. echo '<li>Age : '. $student['Karim']['age']. '</li>';
  203. echo '</ol>';
  204.  
  205. // ============Jabbar Details=================
  206. echo '<h3>Name of Student : Jabbar</h3> ';
  207.  
  208. echo '<ol>';
  209. echo '<li>Roll : '. $student['Jabbar']['roll']. '</li>';
  210. echo '<li>Group : '. $student['Jabbar']['group']. '</li>';
  211. echo '<li>Age : '. $student['Jabbar']['age']. '</li>';
  212. echo '</ol>';
  213.  
  214.  
  215.  
  216. // For loop increament
  217. echo'<h1> For loop increament </h1>';
  218.  
  219. for($i=1; $i<=20; $i++){
  220. echo $i. ', ';
  221.  
  222. }
  223.  
  224.  
  225. // For loop decreament
  226. echo'<h1> For loop decreament </h1>';
  227.  
  228. for($i=20; $i>=1; $i--){
  229. echo $i. ', ';
  230.  
  231. }
  232.  
  233.  
  234.  
  235. // For loop even number
  236. echo'<h1> For loop even number </h1>';
  237.  
  238. for($i=2; $i<=20; $i+=2){
  239. echo $i. ', ';
  240.  
  241. }
  242.  
  243.  
  244.  
  245. // For loop odd number
  246. echo'<h1> For loop odd number </h1>';
  247.  
  248. for($i=1; $i<=20; $i+=2){
  249. echo $i. ', ';
  250.  
  251. }
  252.  
  253.  
  254.  
  255. // While loop
  256. echo'<h1> while loop </h1>';
  257.  
  258. $i=1;
  259.  
  260. while( $i<=20 ){
  261. echo $i. ', ';
  262. $i++;
  263. }
  264.  
  265.  
  266. // Foreach loop
  267. echo'<h1> Foreach loop </h1>';
  268.  
  269.  
  270. $father = array('Rahim'=>30, 'Karim'=>40, 'Jabbar'=>45);
  271.  
  272. foreach($father as $sons=>$age){
  273.  
  274. echo $sons. ' is '. $age. ' years old. <br>';
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement