Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-25 09:09:23
Original
788 people have browsed it
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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template