php: Array keys case *insensitive* lookup?

前端 未结 12 1958
予麋鹿
予麋鹿 2020-12-25 10:30
$myArray = array (\'SOmeKeyNAme\' => 7);  

I want $myArray[\'somekeyname\'] to return 7.
Is there a way to do this

12条回答
  •  不思量自难忘°
    2020-12-25 11:26

    You could loop through the array manually and search for a match.

    foreach( $myArray as $key => $value ) {
        if( strtolower( $key ) == 'somekeyname' ) {
            // match found, $value == $myArray[ 'SOmeKeyNAme' ]
        }
    }
    

提交回复
热议问题