Core\Arr::keys
Gives you every key of an array, as a list.
The keys come back in the order they were put in, and the list they come back in is a fresh array you can walk, count or change without touching the array you asked about.
Every key is text. An array with number keys gives you "0", "1" and so on, and a list gives you its positions written the same way. This is what the keys of a Novis array always are, so nothing is converted on the way out.
An array with no entries gives you an array with no entries.
Parameters
$aarray<T>The array whose keys are wanted.
Return value
Returns array<string>. A list of the keys as strings. "10" stays "10" and is never an int. An empty array gives the empty array.
Examples
The names in an array
<?nvs// Shows how to read the keys of an array.
array<string> $user = ['name' => 'Ada', 'city' => 'Wien', 'job' => 'engineer'];
// The keys come back in the order they were put in. This prints// name, city, job.echo Core\Str::join(Core\Arr::keys($user), ', '), "\n";
foreach (Core\Arr::keys($user) as string $key) { echo $key, ' = ', $user[$key], "\n";}name, city, jobname = Adacity = Wienjob = engineerThe keys are always text
<?nvs// Shows what the keys of a list look like. `Core\Arr::keys` always gives you// text, so the positions of a list come back as "0", "1" and "2".
array<string> $colours = ['red', 'green', 'blue'];
// This prints 0|1|2.echo Core\Str::join(Core\Arr::keys($colours), '|'), "\n";
// The keys of an array with no entries are an array with no entries, so this// prints 0.array<string> $empty = [];echo Core\Arr::count(Core\Arr::keys($empty)), "\n";0|1|20Fields the page does not know
<?nvs// Shows how a page finds the fields a form sent that it does not know about.
array<string> $sent = ['name' => 'Ada', 'city' => 'Wien', 'colour' => 'red'];array<string> $known = ['name', 'city'];
foreach (Core\Arr::keys($sent) as string $field) { if (!Core\Arr::contains($known, $field)) { echo 'unknown field: ', $field, "\n"; }}unknown field: colour