本文整理汇总了PHP中CMbArray::flip方法的典型用法代码示例。如果您正苦于以下问题:PHP CMbArray::flip方法的具体用法?PHP CMbArray::flip怎么用?PHP CMbArray::flip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMbArray
的用法示例。
在下文中一共展示了CMbArray::flip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: selectConstants
/**
* Return the selected constants in an formatted array (see getConstantsByRank to see the format)
*
* @param array $selection The constant you want to select
* @param string $type 'form' or 'graph'
* @param CMbObject|string $host Host from which we'll get the configuration
*
* @return array
*/
static function selectConstants($selection, $type = 'form', $host = null)
{
if ($host) {
$show_cat_tabs = CConstantesMedicales::getHostConfig("show_cat_tabs", $host);
} else {
$show_cat_tabs = CConstantesMedicales::getConfig("show_cat_tabs");
}
$constants_by_rank = self::getRanksFor($type, $host);
$list_constants = CConstantesMedicales::$list_constantes;
// Keep only valid constant names
$constants_by_rank = array_intersect_key($constants_by_rank, $list_constants);
$constants_by_rank = CMbArray::flip($constants_by_rank);
ksort($constants_by_rank);
$result = array();
foreach ($constants_by_rank as $_rank => $_constants) {
if ($_rank === -1) {
continue;
}
foreach ($_constants as $_constant) {
if (strpos($_constant, "_") === 0) {
continue;
}
if ($show_cat_tabs) {
$_type = $list_constants[$_constant]["type"];
if (!array_key_exists($_type, $result)) {
$result[$_type] = array();
}
if (!in_array($_constant, $selection)) {
$rank = -1;
} else {
$rank = $_rank;
}
if (!array_key_exists($rank, $result[$_type])) {
$result[$_type][$rank] = array();
}
$result[$_type][$rank][] = $_constant;
} else {
if (!array_key_exists('all', $result)) {
$result['all'] = array();
}
if (!in_array($_constant, $selection)) {
$rank = -1;
} else {
$rank = $_rank;
}
if (!array_key_exists($rank, $result['all'])) {
$result['all'][$rank] = array();
}
$result['all'][$rank][] = $_constant;
}
}
}
foreach ($result as $_type => $_ranks) {
if (array_key_exists(-1, $result[$_type])) {
$unselected_constants = $result[$_type][-1];
unset($result[$_type][-1]);
$result[$_type]["hidden"] = $unselected_constants;
}
if (array_key_exists(-1, $result[$_type])) {
unset($result[$_type][-1]);
}
}
return $result;
}
示例2: testFlip
public function testFlip()
{
$this->assertEquals(array("val" => array("key")), $this->stub->flip(array("key" => "val")));
$this->assertEquals(array("val" => array("key", "key2")), $this->stub->flip(array("key" => "val", "key2" => "val")));
}