Home  >  Article  >  Backend Development  >  A small mistake that is easy to overlook, have you ever made it?

A small mistake that is easy to overlook, have you ever made it?

WBOY
WBOYOriginal
2016-07-25 09:09:23733browse
foreach array value modification
  1. /**
  2. * Note the difference in foreach values ​​
  3. */
  4. $arr = array(1,2,3,4);
  5. echo "foreach traverses array 1:
    ";
  6. foreach( $arr as $val) {
  7. $val = $val*2;
  8. }
  9. var_dump($arr);
  10. echo "
    foreach traverses array 2:
    ";
  11. foreach( $arr as &$val) {
  12. $val = $val*2;
  13. }
  14. var_dump($arr);
  15. /*end of php*/
Copy code


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