Skip to content

Instantly share code, notes, and snippets.

@igorsgm
Created December 3, 2016 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorsgm/8a105acd3f8dffc36c3e7aa384d27c48 to your computer and use it in GitHub Desktop.
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
<?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