Skip to content

Instantly share code, notes, and snippets.

@Jul10l1r4
Created December 14, 2017 09:14
Show Gist options
  • Save Jul10l1r4/bd028f2c3e08d2933082d9f551eebe46 to your computer and use it in GitHub Desktop.
Save Jul10l1r4/bd028f2c3e08d2933082d9f551eebe46 to your computer and use it in GitHub Desktop.
Array_reduce.php created by Jul10l1r4 - https://repl.it/@Jul10l1r4/Arrayreducephp
<?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