4
I’m creating a Seeder
to the Laravel
insert values into a table N para N
.
I am riding the array
in one way, but I need it to "become" in another. This is because I want to avoid repeating constant code (typing repeatedly the same items from array
.
The array
what I have is this:
$niveis[3] = [
$can('VendaController@getIndex'),
$can('VendaController@anyEditar'),
$can('VendaController@anyCriar'),
];
$niveis[14] = [
$can('ProdutoController@getIndex'),
$can('UsuarioController@anyEditar'),
$can('UsuarioController@anyCriar'),
];
This generates a array
thus:
[
3 => [1, 55, 87],
14 => [45, 78, 101]
]
But I need that from that array
, I can ride him like this:
[
[ 'nivel_id' => 3, 'permissao_id' => 1],
[ 'nivel_id' => 3, 'permissao_id' => 55],
[ 'nivel_id' => 3, 'permissao_id' => 87],
// E assim por diante
]
I mean, I need to transform the key
in nivel_id
with its value, and repeat as long as it has some value within the array
concerning her.
How to do this in PHP, in a less complicated way possible?
Good question +1
– rray
@rray I have the small impression that it will take us to a
array_map
two-parameter– Wallace Maxters