I have a static class
Tools
getMsg()
private $Msg = array()
public static function getMsg()
{
return $this->Msg;
}
Tools::getMsg()['key'] = $this->message;
array_search — Searches the array for a given value and returns the
first corresponding key if successful
$Msg = array('Class1' => 'File does not exist',
'Class2' => 'Error in timestamp format')
To access an array, you do not need to use a built-in function. Simply access the array as follows.
$arr = array('foo' => 42, 'bar' => 'rab', 'baz' => false); // example array
echo $arr['bar']; // will output 'rab'
$key = 'foo';
echo $arr[$key]; // will output 42
As a sidenote: you cannot use $this
in a static context. Use self::$Msg
and declare $Msg
as private static $Msg
, or make the access not static at all. Your code could be along the following lines.
private static $Msg = array();
public static function getMsg()
{
return self::$Msg;
}