Created
December 14, 2017 09:14
-
-
Save Jul10l1r4/bd028f2c3e08d2933082d9f551eebe46 to your computer and use it in GitHub Desktop.
Array_reduce.php created by Jul10l1r4 - https://repl.it/@Jul10l1r4/Arrayreducephp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$users = [ | |
[ 'idade' => 29, 'nome' => 'Marcos lucim' ], | |
[ 'idade' => 20, 'nome' => 'Marcelo ' ], | |
[ 'idade' => 50, 'nome' => 'Marcos dougras' ], | |
]; | |
function passa ( $val, $w ){ | |
$val["idade"] += $w["idade"];// aqui ele vai pegar o valor do array e irá somar. | |
return $val; | |
} | |
$val_saida = array_reduce( $users, "passa" ); | |
// Mudei o nome da variavel, por motivo de futuras alterações | |
print_r($val_saida); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment