Given this array:
$columns = [
['data' => 'id', 'name' => 'id', 'title' => 'ID', 'class' => 'text-center text-shrink', 'orderable' => false, 'searchable' => false],
['data' => 'name', 'name' => 'name', 'title' => 'Nome', 'default' => true],
['data' => 'email', 'name' => 'email', 'title' => 'E-mail'],
['data' => 'created_at', 'name' => 'created_at', 'title' => 'Creato il', 'class' => 'text-center'],
['data' => 'updated_at', 'name' => 'updated_at', 'title' => 'Aggiornato il', 'class' => 'text-center'],
['data' => 'action', 'name' => 'action', 'title' => 'Azioni', 'class' => 'text-center text-shrink', 'orderable' => false, 'searchable' => false],
];
How do I retrieve the key of the only item that has 'default' => true
(it should be 1
in this case)? I could do it with a loop, but isn't there an easy way for trivial task like this? Please notice that I can also use Laravel helpers
Please notice that this is not a duplicate of a previous question: here I am sure that the default
subkey exists in only one array item and not in the others, so I can't use array_column()
and then get the one with a certain value
Thank you