Home  >  Article  >  Backend Development  >  php-Is my understanding correct? The reason why $b outputs 1 is because $a defaults to 0?

php-Is my understanding correct? The reason why $b outputs 1 is because $a defaults to 0?

PHP中文网
PHP中文网Original
2016-08-10 08:49:081397browse

  php

  • <?phpfunction test (&$b){    $b++;    echo $b.&#39;&#39;;
    }test($a);$a=100;echo $a;

Reply content:

This code has been changed to better understand the changes in $a:

<?php
function test (&$b){
$b++;
echo $b.&#39;
&#39;;
}
test($a);
echo $a;
$a=100;
echo $a;

Yes, php will initialize a default value for unassigned code. For integers, This value is 0

The initialization value is the same as java.
What should I pay attention to when studying? I think the most important thing is to apply what you have learned, practice more, and write some code that has practical significance. Don’t write too much helloworld-level code, let alone go overboard and create some weird test programs, and pay more attention to real-world problems. .

The above is php - is my understanding correct? The reason why $b outputs 1 is because $a defaults to 0? For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn