Skip to content

Instantly share code, notes, and snippets.

@tim-cotten
Created March 3, 2021 16:44
Show Gist options
  • Save tim-cotten/bd442fb6d02844833d6b757ba1f53ee4 to your computer and use it in GitHub Desktop.
Save tim-cotten/bd442fb6d02844833d6b757ba1f53ee4 to your computer and use it in GitHub Desktop.
PHP Bugs: Undefined Indexes and More Misspellings (Proof 5)
<?php
// Simple array of mixed keys and values
$arr = array(
0 => 'First',
1 => 'Second',
'Alpha' => 'Greek',
'FUN' => true,
'00' => 'Last',
0.328932 => 'test float',
32892.232 => 'test float 2'
);
$keys = array_keys($arr);
foreach ($keys as $key) {
echo "{$key} is " . gettype($key) . " => {$arr[$key]}\n";
}
// Output:
// 0 is integer => test float
// 1 is integer => Second
// Alpha is string => Greek
// FUN is string => 1
// 00 is string => Last
// 32892 is integer => test float 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment