⊗ppPmScPC 215 of 447 menu

Changing Function Parameters in PHP

Changing variables passed as parameters to a function will not lead to changes in these variables outside:

<?php function func($bbb) { $bbb = 2; } $aaa = 1; func($aaa); echo $aaa; // 1 ?>

This, of course, works even if the external and internal variables have the same name:

<?php function func($num) { $num = 2; } $num = 1; func($num); echo $num; // 1 ?>

Tell me what the result of the code execution will be:

<?php $aaa = 'a'; function func($bbb) { $bbb = 'b'; } func($aaa); echo $aaa; ?>

Tell me what the result of the code execution will be:

<?php $aaa = 'a'; function func($bbb) { $bbb = 'b'; } func($aaa); echo $bbb; ?>

Tell me what the result of the code execution will be:

<?php $str = 'a'; function func($str) { $str = 'b'; } func($str); echo $str; ?>

Tell me what the result of the code execution will be:

<?php $arr = [1, 2, 3, 4, 5]; function func($arr) { $arr[0] = '!'; } func($arr); var_dump($arr); ?>
byenru