把数组翻译PHP类 [英] Put array translation in php class
问题描述
这是我的问题:
我已经包含在我的网站翻译的每一页的数组。
该数组由:
I have an array included in every page of my site with the translations. The array is composed:
$translation = array();
$translation['0'] = 'aaa';
$translation['1'] = 'bbb';
$translation['2'] = 'ccc';
$translation['3'] = 'ddd';
$translation['4'] = 'eee';
我对每种语言的文件 - 数组长
I have a file for each language - the array is long.
如果我把一个类里的数组元素,我得到一个错误未定义变量。
If I call an array element inside a class, I get an error "Undefined variable".
我如何能够通过外部数组元素上我的课?
How I can pass the external array elements to my class?
感谢。
Ginetto
推荐答案
您没有指定的语言,但假设它是PHP,通过引用(不是值)和放大器传递数组变量; $翻译的争论例如:
You didn't specify the language, but for assuming it's PHP, either pass the array variable by reference (not value) with &$translation in the arguments eg.
$my_object->doSomething(&$translation_arg);
到类方法(或构造函数),或者你可以用你的方法全球$翻译',即访问全局变量。
to your class method (or constructor) OR you can access global variables by using 'global $translation' in your methods ie.
class MyClass {
global $translation;
...
}
第一种方法通常是更好的。
The first method is usually better.
这篇关于把数组翻译PHP类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!