本文整理汇总了PHP中Locale::getLocalePrecedence方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::getLocalePrecedence方法的具体用法?PHP Locale::getLocalePrecedence怎么用?PHP Locale::getLocalePrecedence使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::getLocalePrecedence方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
function &getLocalizedData($key)
{
$localePrecedence = Locale::getLocalePrecedence();
foreach ($localePrecedence as $locale) {
$value =& $this->getData($key, $locale);
if (!empty($value)) {
return $value;
}
unset($value);
}
// Fallback: Get the first available piece of data.
$data =& $this->getData($key, null);
if (!empty($data)) {
return $data[array_shift(array_keys($data))];
}
// No data available; return null.
unset($data);
$data = null;
return $data;
}
示例2: foreach
/**
* Get a piece of data for this object, localized to the current
* locale if possible.
* @param $key string
* @return mixed
*/
function &getLocalizedData($key)
{
$localePrecedence = Locale::getLocalePrecedence();
foreach ($localePrecedence as $locale) {
$value =& $this->getData($key, $locale);
if (!empty($value)) {
return $value;
}
unset($value);
}
// Fallback: Get the first available piece of data.
$data =& $this->getData($key, null);
if (!empty($data)) {
// WARNING: Collapsing the following into a single line causes PHP 5.0.5 to die.
$locales = array_keys($data);
$firstLocale = array_shift($locales);
return $data[$firstLocale];
}
// No data available; return null.
unset($data);
$data = null;
return $data;
}