I have a function that looks like this
protected function getAllData(string $tableName, string $collectionKey): array
{
// Some logic here to get records from database and store them in $records...
$data = [
'count' => count($records),
$collectionKey => [],
];
foreach ($records as $record) {
$data[$collectionKey][] = [
'name' => $record['name'],
'value' => $record['value'],
];
}
return $data;
}
How can I define the array key $collectionKey
which is passed in as a parameter`
/**
* @param string $tableName
* @param string $collectionKey
* @return array{
* count: int<0, max>,
* '?????': list<array{ <-- How?
* name: string,
* value: string,
* }>
* }
*/