I wonder if it's possible to assign an array key to a value of another key, for example:
$array = array(
'key1' => 'Foo'
'key2' => $array['key1']
);
Or something like that, but I'm just getting errors about PHP expecting other stuff:
Parse error: syntax error, unexpected '$TYPE_LOCALES' (T_VARIABLE), expecting identifier (T_STRING) or class (T_CLASS) in …
The class where the array in question is located is as follows:
final class UserTypes {
const TYPE_ADMINISTRATOR = 1;
const TYPE_CALL_CENTER_OP = 2;
const TYPE_SALES_LEADER = 3;
const TYPE_SALES_OP = 4;
const TYPE_LOCALE_DEFAULT = 'default';
const TYPE_LOCALE_ES = 'es';
private static $TYPE_LOCALES = array(
TYPE_LOCALE_DEFAULT => array(
TYPE_ADMINISTRATOR => 'administrador',
TYPE_CALL_CENTER_OP => 'agente de call center',
TYPE_SALES_LEADER => 'partner líder',
TYPE_SALES_OP => 'partner operador',
),
TYPE_LOCALE_ES => self::$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
);
}
And as you can see, I'm trying to make the 'es' key equal to 'default'. But I don't want to extract the default array (defining it outside the array) and then just using it inside, since there will be more arrays that will each be equal to any other array.
Update:
This is what I've tried already:
TYPE_LOCALE_ES => self::$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => UserTypes::$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => $TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => &$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => &self::$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => self::&$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => &UserTypes::$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
TYPE_LOCALE_ES => UserTypes::&$TYPE_LOCALES[TYPE_LOCALE_DEFAULT]
Without luck.
self::$TYPE_LOCALES[TYPÊ_LOCALE_DEFAULT]to 1, then it's syntactically right.1? Is that an example? I know a constant will work but that's not what I'm trying to get.constantfor a reason. You would need something like$arr[TYPE_LOCALE_DEFAULT] => array()for instance.