I'm trying out some laravel helpers and I realize that either I'm doing something wrong or this is not working, I use laravel 5.2
This is my code.
public function coleccionArrayAlfanumerico()
{
$resultado = collect(['pepino','porche','ramon','camisa','japones','movil','aprende el arte del pnl','Pentium IV','pescaderia']);
return $resultado;
}
public function coleccionArrayClaves()
{
$clave = collect(['fruta', 'coche', 'nombre','ropa', 'idioma', 'tecnologia','libro', 'ORDENADOR', 'establecimiento']);
return $clave;
}
public function flatMap()
{
$claves = $this->coleccionArrayClaves();
$valores = $this->coleccionArrayAlfanumerico();
$combinados = $claves->combine($valores);
$flatmappeado = $combinados->flatMap(function($values){
return array_map('strtoupper',$values);
});
$resultado = $flatmappeado->all();
dd($resultado);
}
The error is:
array_map(): Argument #2 should be an array
I do not understand very well why, I have based on the example of the documentation and I have created arrays manually so as not to have to take data from the database to avoid major problems.
Any ideas?
------------------------------ EDITED ---------------- ------------
The result of "combined" is
Collection {#252 ▼
#items: array:9 [▼
"fruta" => "pepino"
"coche" => "porche"
"nombre" => "ramon"
"ropa" => "camisa"
"idioma" => "japones"
"tecnologia" => "movil"
"libro" => "aprende el arte del pnl"
"ORDENADOR" => "Pentium IV"
"establecimiento" => "pescaderia"
]
}
Doing a dd ($ values) or a var_dump here
$flatmappeado = $combinados->flatMap(function($values){
dd($values);
return array_map('strtoupper',$values);
});
Its result is "cucumber", that is, the first element of the array. Putting "$ values" or putting "$ values" the result is the same, that is "cucumber".
Shaz, it really draws attention that if you seem to be calling flatmap inside yourself, but I'm really catching the same example of documentation, just like that, that's why I'm surprised it does not work.