dir.by  
Поиск >>

Компьютер, программы
→
PHP (Programming Language for Fast Writing of a Web Site)
 Passing parameters to a function in PHP 
посмотрели 6937 раз
обновлено: 5 December 2024
1) Pass parameters by value to a function
Any parameter that is passed to the function does not change the value when the function exits.
That is, when we pass a parameter to a function, a copy of this parameter is created and inside the function we work with a copy of the parameter.
Example
  PHP  
<?php

     // declare a function
     function SetValue($x)
     {
          $x = 10;
     }

     // create a variable
     $a = 20;

     // call the function
     SetValue($a);

     print($a); // we will see on the screen 20
?>
2) Pass parameters by reference to the function
To pass a parameter to a function by reference, you need to use &
When you pass a parameter to a function by reference, such a parameter is passed inside the function and we work with this parameter.
When you exit the function, the parameter changes the value
Example
  PHP  
<?php

     // declare a function
     function SetValue(& $x)
     {
          $x = 10;
     }

     // create a variable
     $a = 20;

     // call the function
     SetValue($a);

     print($a); // we will see on the screen 10
?>
 
← Previous topic
Function in PHP. Example: function CalculateSum($value1, $value2) { ... }
 
Next topic →
Pass a function as a parameter to a function | PHP
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
PHP Study
• What is PHP ?
Function
• Function in PHP. Example: function CalculateSum($value1, $value2) { ... }
• Passing parameters by value and by reference to a function in PHP
• Pass a function as a parameter to a function | PHP
Unnamed function
• Anonymous function (no name). Function pointer in PHP
• Pass the unnamed function as a parameter to the | using use (...) the unnamed function sees the variable above | PHP
Arrays
• Array in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
• Look for an element in an array in PHP | array_search
Key-value arrays
• Array (key-value) in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
Regular expressions
• Regular expressions
PHP Server
• Create an html file and javascript sends a post request to the php server. PHP server makes the answer | Why on php server $_REQUEST or $_POST array is empty
Framworks (frameworks)
• Zend Framework (PHP framework)
• Yii (PHP framework)
• CakePHP (framework)

  Ваши вопросы присылайте по почте: info@dir.by