Created
December 3, 2016 02:37
-
-
Save igorsgm/8a105acd3f8dffc36c3e7aa384d27c48 to your computer and use it in GitHub Desktop.
Função callback do array_map para transformar um array em string utilizando a chave e o valor, sem foreach
This file contains hidden or 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 | |
$myArray = array(1 => Igor, 2 => Moraes); | |
$string = array_map(function ($key, $value) { | |
return sprintf("('%s', '%s')", $key, $value); | |
}, array_keys($myArray), $myArray | |
); | |
var_dump($string); // (1, Igor), (2, Moraes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment