pr5 - 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 pr5.php

  1. <?php
  2.  
  3. error_reporting(-1);
  4.  
  5. /* 
  6. $rates = array(3, 5, 3, 2, 1, 8, 4, 3, 4, 3, 2, 3);
  7.  
  8. $ratesSum = array_sum($rates);
  9. $ratesCount = count($rates); 
  10. $averageRate = array_sum($rates)/count($rates); 
  11.  
  12. echo "Анону поставили {$ratesCount} оценок, их сумма = {$ratesSum}\nСредний балл — {$averageRate}\n";
  13.  
  14.  
  15.  
  16.  
  17. $anonHeight = 169; 
  18.  
  19. $classmates = array(
  20.         'Антон'    =>      172,
  21.         'Семен'    =>      165,
  22.         'Лена'      =>      189,
  23.         'Иван'      =>      171,
  24.         'Петр'      =>      182,
  25.         'Сидор'    =>      176,
  26.         'Аня'        =>      180,
  27.         'Таня'      =>      179,
  28.         'Маня'      =>      171
  29. );
  30.  
  31. $number = 0; 
  32.  
  33. foreach ($classmates as $name => $height) {
  34.     if ($anonHeight<$height){
  35.         $number+=1;
  36.     }
  37.     echo "Имя: {$name}, рост: {$height} см.\n";
  38. }
  39.  
  40. echo "В классе {$number} человек выше анона\n";*/
  41.  
  42.  
  43.  
  44.  
  45. /*$answers = array(
  46.         1       =>      'да',
  47.         2       =>      'нет',
  48.         3       =>      'не знаю',
  49.         4       =>      'никогда',
  50.         5       =>      'это зависит от тебя',
  51.         6       =>      'спроси анона'
  52. );
  53.  
  54. $question = 'Выучу ли я PHP без регистрации и СМС?';
  55. $a=array_rand($answers);
  56.  
  57. echo "Вопрос: {$question}\n";
  58. echo "Ответ: {$answers[$a]}\n";*/
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. /*$letters = array(
  66.     'ко',   'и',    'дзу',  'ми',
  67.     'са',   'ку',   'ра',   'да',
  68.     'чи',   'а',    'ки',   'ми',
  69.     'на',   'го',   'ха',   'ру'
  70. );
  71.  
  72. $name = '';
  73.  
  74. for ($i = 1; $i <= 4; $i++) {   
  75.  
  76.     $random = array_rand($letters); 
  77.     $randomText = $letters[$random];
  78.     
  79.     echo "Выпало число {$random}, слог {$randomText}\n";
  80.     $name= $randomText . $name;
  81. }
  82.  
  83. echo "------\n";
  84. echo "Советую имя: {$name} - не прогадаешь!\n";*/
  85.  
  86.  
  87.  
File Description
  • pr5
  • PHP Code
  • 27 Jan-2023
  • 1.66 Kb
You can Share it: