1
I usually use the function array_map
to be able to do something similar to the "list comprehension" of python
Something like:
$meses = function($mes)
{
return sprintf('02%s/%s', $mes, date('Y'));
}
$arrayFormatado = array_map($meses, range(1, 12));
// Retorna: array(){ '01/2015', '02/2015', ...}
But now, looking closely at the Manual, I realized that after the first parameter the number of arrays
past can be infinite:
array array_map ( callback $callback , array $arr1 [, array $... ] )
What is the purpose of this?
What are the arrays ?
– Edilson
I’m still asking myself - "What do you want to know for sure" : http://stackoverflow.com/questions/3432257/difference-between-array-map-array-walk-and-array-filter
– Edilson
I think by showing the traditional usage difference and wondering why this function accepts N arrays parameters I’ve made it clear enough.
– Wallace Maxters
Not that I want to appear arrogant or ignorant, but on the very page of PHP.net, the examples are more than explicit, and explain the function and the infinite arguments it can receive. And besides, your question is also the answer you seek, in my view clear ! Maybe I’m misunderstanding, but that’s why I just showed that difference. Take a look at the image before example #4 : http://php.net/manual/en/function.array-map.php this might help with the question. And please don’t misunderstand me, I have the best intentions.
– Edilson
@Edilson, it is, manual in English. It seems to me that (almost always) the Manual in Portuguese comes missing something. And the Handbook doesn’t always serve to teach you anything that works in practice, or even say for sure How a function works. So I prefer to ask here :p
– Wallace Maxters
Ah, how could I forget that -, I almost never read the manual in Portuguese, now for sure I was ignorant, I did not evaluate the conditions before. However I think the @Ivan Ferrer answer will help you.
– Edilson