thinkphp
thinkphp copied to clipboard
NULL returns when in_array function with global static variable!
Hello, I found out a mistake which is when using php funciton "in_array" to search the global static variable! It like this: First, define a array:
`$example_array = array('Index' => 'index');`
Then:
$status = in_array(ACTION_NAME, $example_array[CONTROLLER_NAME]);
Whatever the action is index or not when the controller is Index, it always returns NULL(the $status). I tried another way to solve it:
$action = ACTION_NAME;
$actions = $example_array[CONTROLLER_NAME];
$status = in_array($action, $actions);
This method will return NULL or bool(true) correctly.
the usecase of in_array() is "bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )"
you used it in the wrong way 。because the second parameter needs to be array not string,however you set it with a string