$ rows = array ( 1 , 2 , 3 ) ;
$ total = 0 ;
// Case of times - use ($ total) without reference
array_walk ( $ rows , function ( $ row ) use ( $ total ) {
$ total + = $ row ;
} ) ;
echo "Total is $ total \ n " ;
// Case two - use (& $ total) by reference
array_walk ( $ rows , function ( $ row ) use ( & $ total ) {
$ total + = $ row ;
} ) ;
echo "Total is $ total \ n " ;
Total is 0 Total is 6
Source: https://habr.com/ru/post/69003/
All Articles