lab5-1 - 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 lab5-1.php

  1. <?php
  2.         //Зададим функцию:
  3.         function hello($name) { //укажем здесь параметр $name, в котором будет лежать имя человека
  4.                 //Введем переменную $text, в которую запишем всю фразу:
  5.                 $text = 'Привет, '.name.'!';
  6.        
  7.                 /*
  8.                         Укажем функции с помощью инструкции 'return', 
  9.                         что мы хотим, чтобы она ВЕРНУЛА содержимое переменной $text:
  10.                 */
  11.                 return $text;
  12.         }
  13.        
  14.         //Теперь вызовем нашу функцию и запишем значение в переменную $message:
  15.         $message = hello('Дима');
  16.        
  17.         //И теперь в переменной $text лежит 'Привет, Дима!':
  18.         echo $message; //убедимся в этом
  19.        
  20.         //Поздороваемся сразу с группой людей из трех человек:
  21.         echo hello('Вася'.' '.hello('Петя').' '.hello('Коля'));
  22. ?>
  23.  
  24.  
File Description
  • lab5-1
  • PHP Code
  • 01 Dec-2022
  • 1004 Bytes
You can Share it: