lab1 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of lab1.php

  1. <?php
  2. #1.1
  3. $a = 10;
  4. echo $a."\n";
  5. echo "\n";
  6. #1.2
  7. $b = 20;
  8.  
  9. echo ($b - $a)."\n";
  10. echo ($b + $a)."\n";
  11. echo ($b * $a)."\n";
  12. echo ($b / $a)."\n";
  13. echo "\n";
  14. #1.3
  15. $c = 40;
  16. $d = 60;
  17. $result = $c + $d;
  18. echo $result."\n";
  19. echo "\n";
  20. #1.4
  21. $a1 = 3;
  22. $b1 = 1;
  23. $c1 = $a1 - $b1;
  24. $d1 = 15;
  25. $result1 = $c1 + $d1;
  26. echo $result1."\n";
  27. echo "\n";
  28.  
  29. #2.1
  30. $text = "Привет, Мир!";
  31. echo $text."\n";
  32.  
  33. #2.2
  34. $text1 = "Привет, ";
  35. $text2 = "Мир!";
  36. echo $text1.$text2."\n";
  37.  
  38. #2.3
  39. $name = "Вероника";
  40. echo "Привет, $name!"."\n";
  41.  
  42. #2.4
  43. $age = "21";
  44. echo "Мне $age год"."\n";
  45. echo "\n";
  46.  
  47.  
  48. #3.1
  49. $text3 = "HelloWorld";
  50. #3.2
  51. echo $text3[1], $text3[5], $text3[7]."\n";
  52. echo "\n";
  53.  
  54. #3.3
  55. echo str_replace($text3[0], "T", $text3)."\n";
  56. echo "\n";
  57.  
  58. #3.4
  59. $num = '8568';
  60. echo array_sum(str_split($num))."\n";
  61. echo "\n";
  62.  
  63. #4.1
  64. echo (60 * 60 * 24)."\n";
  65. echo "\n";
  66.  
  67. #4.2
  68.  
  69. $hour = 19;
  70. $min = 43;
  71. $second = 07;
  72. echo "$hour:$min:$second"."\n";
  73. echo "\n";
  74.  
  75. #4.3
  76. $z = 4;
  77. echo pow($z, 2)."\n";
  78. echo "\n";
  79.  
  80. #4.4
  81. $var = 47;
  82. $var += 7;
  83. $var -= 18;
  84. $var *= 10;
  85. $var /= 20;
  86. echo $var."\n";
  87. echo "\n";
  88.  
  89. #4.5
  90. $text = 'Я';
  91. $text .= ' хочу';
  92. $text .= ' знать';
  93. $text .= ' PHP!';
  94. echo $text;
  95. ?>
File Description
  • lab1
  • PHP Code
  • 18 Jan-2023
  • 1.16 Kb
You can Share it: