本文整理汇总了PHP中arr::is_assoc方法的典型用法代码示例。如果您正苦于以下问题:PHP arr::is_assoc方法的具体用法?PHP arr::is_assoc怎么用?PHP arr::is_assoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arr
的用法示例。
在下文中一共展示了arr::is_assoc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Ensures there is a choices array set
*
* @param array $options
*/
public function __construct($options = array())
{
parent::__construct($options);
// Ensure we have choices to gather values from
if (empty($this->choices)) {
throw new Kohana_Exception('Field_Enum must have a `choices` property set');
}
// Convert non-associative values to associative ones
if (!arr::is_assoc($this->choices)) {
$this->choices = array_combine($this->choices, $this->choices);
}
}
示例2: assoc2xml
/**
* Convert an associative array to XML
* If array is multi-dimensional, it will attempt to detect keyed vs ordered and build XML accordingly
*
* @param array associative array
* @param string root element
* @return string XML String
*/
public static function assoc2xml($assoc, $root_element = "xml")
{
if (!is_array($assoc) || count($assoc) == 0) {
return "<" . $root_element . " />\n";
}
foreach ($assoc as $key => $value) {
if ($value === YES) {
$value = "true";
} else {
if ($value === NO) {
$value = "false";
} else {
if (!is_array($value) && strlen($value) == 0) {
$xml .= "<" . $key . " />\n";
continue;
} else {
if (is_array($value)) {
if (arr::is_assoc($value)) {
$xml .= xml::assoc2xml($value, $key);
} else {
$xml .= xml::ordered2xml($value, $key);
}
continue;
} else {
if (self::use_cdata($value)) {
$value = "<![CDATA[" . $value . "]]>";
} else {
$value = htmlentities($value);
}
}
}
}
}
$xml .= "<" . $key . ">" . $value . "</" . $key . ">\n";
}
return "<" . $root_element . ">\n" . xml::pad($xml) . "</" . $root_element . ">\n";
}
示例3: debug_var
/**
* Returns a single line representation of a variable. Internally, this is
* used only for showing function arguments in stack traces.
*
* echo Kohana::debug_var($my_var);
*
* @param mixed variable to debug
* @return string
*/
public static function debug_var($var)
{
switch (gettype($var)) {
case 'null':
return 'NULL';
break;
case 'boolean':
return $var ? 'TRUE' : 'FALSE';
break;
case 'string':
return var_export($var, TRUE);
break;
case 'object':
return 'object ' . get_class($var);
break;
case 'array':
if (arr::is_assoc($var)) {
return print_r($var, TRUE);
}
return 'array(' . implode(', ', array_map(array(__CLASS__, __FUNCTION__), $var)) . ')';
break;
default:
return var_export($var, TRUE);
break;
}
}
示例4: parse_plist_value
private static function parse_plist_value($value, $key = false, $tab_level = 0)
{
static $data_pattern = '/([0-9]{4}\\-[0-9]{2}\\-[0-9]{2}T[0-9]{2}\\:[0-9]{2}\\:[0-9]{2})(Z|[\\-\\+][0-9]{2}\\:[0-9]{2})/';
// Determine the type
switch (true) {
// integer
case is_numeric($value) && is_float($value) === FALSE:
$svalue = '<integer>' . $value . '</integer>';
break;
// real
// real
case is_numeric($value) && is_float($value) === TRUE:
$svalue = '<real>' . $value . '</real>';
break;
// date
// date
case !is_array($value) && preg_match($data_pattern, $value):
$value = preg_replace($data_pattern, '$1Z', $value);
$svalue = '<date>' . $value . '</date>';
break;
// string
// string
case is_string($value):
// TODO: correctly parse &
$svalue = '<string>' . htmlspecialchars(iconv('UTF-8', 'UTF-8//IGNORE', $value), ENT_NOQUOTES, 'UTF-8') . '</string>';
break;
// true
// true
case $value === TRUE:
$svalue = '<true />';
break;
// false
// false
case $value === FALSE:
$svalue = '<false />';
break;
// dict
// dict
case is_array($value) && arr::is_assoc($value) === TRUE:
$svalue = '<dict>' . plist::$eol;
$tab_level++;
foreach ($value as $vkey => $vvalue) {
$svalue .= self::parse_plist_value($vvalue, $vkey, $tab_level);
}
$tab_level--;
$svalue .= self::tabs($tab_level) . '</dict>';
$svalue;
break;
// array
// array
case is_array($value) && arr::is_assoc($value) === FALSE:
$svalue = '<array>' . plist::$eol;
$tab_level++;
foreach ($value as $vvalue) {
$svalue .= self::parse_plist_value($vvalue, FALSE, $tab_level);
}
$tab_level--;
$svalue .= self::tabs($tab_level) . '</array>';
break;
}
return self::tabs($tab_level) . ($key ? '<key>' . $key . '</key>' . plist::$eol . self::tabs($tab_level) : '') . $svalue . plist::$eol;
}
示例5: parse_xml_value
public static function parse_xml_value($value, $tag = '', $tab_level = 0)
{
$svalue = '';
// Determine the type
switch (true) {
// bool
case is_bool($value):
$svalue = "<{$tag}>" . ($value ? "1" : "0") . "</{$tag}>";
break;
// string
// string
case is_string($value):
if (empty($value)) {
$svalue = "<{$tag} />";
} else {
// TODO: correctly parse &
if (stripos($value, '<![CDATA[') === 0) {
$svalue = "<{$tag}>" . iconv('UTF-8', 'UTF-8//IGNORE', $value) . "</{$tag}>";
} else {
$svalue = "<{$tag}>" . htmlspecialchars(iconv('UTF-8', 'UTF-8//IGNORE', $value), ENT_NOQUOTES, 'UTF-8') . "</{$tag}>";
}
}
break;
// assoc array
// assoc array
case is_array($value):
if (empty($value)) {
$svalue = "<{$tag} />";
} elseif (arr::is_assoc($value)) {
if ($tag != '') {
$svalue = '<' . $tag . '>' . arr::$eol;
$tab_level++;
}
foreach ($value as $vkey => $vvalue) {
$svalue .= self::parse_xml_value($vvalue, $vkey, $tab_level);
}
if ($tag != '') {
$tab_level--;
$svalue .= self::tabs($tab_level) . '</' . $tag . '>';
}
} else {
if ($tag != '') {
$svalue = "<{$tag}>" . arr::$eol;
$tab_level++;
}
foreach ($value as $vvalue) {
$svalue .= self::parse_xml_value($vvalue, arr::$xml_default_tag, $tab_level);
}
if ($tag != '') {
$tab_level--;
$svalue .= self::tabs($tab_level) . "</{$tag}>";
}
}
break;
// others
// others
default:
$svalue = "<{$tag}>{$value}</{$tag}>";
break;
}
return self::tabs($tab_level) . $svalue . arr::$eol;
}