Actually, you had the right result, it's just formatted in a different way.
array:2 [▼
0 => "date"
1 => "user_id"
]
is equivalent to:
[
"date",
"user_id"
]
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have an array:
array:2 [
"date" => "2020-01-19"
"user_id" => 123
]
I would like to get the array keys only, like that:
['date', `user_id`]
I tried to use array_keys php but it's not my expected It return :
array:2 [
0 => "date"
1 => "user_id"
]
I also tried to use collection on laravel
$collection = collect(["date" => "2020-01-19",
"user_id" => 123
]);
$keys = $collection->keys();
return $keys->all();
Result:
array:2 [▼
0 => "date"
1 => "user_id"
]
althought the laravel document wrote an example:
$collection = collect([
'prod-100' => ['product_id' => 'prod-100', 'name' => 'Desk'],
'prod-200' => ['product_id' => 'prod-200', 'name' => 'Chair'],
]);
$keys = $collection->keys();
$keys->all();
// ['prod-100', 'prod-200']
Can anybody help to exlain to me how to get
['date', `user_id`]
any response is appreciated !
Actually, you had the right result, it's just formatted in a different way.
array:2 [▼
0 => "date"
1 => "user_id"
]
is equivalent to:
[
"date",
"user_id"
]
Please or to participate in this conversation.