本文整理匯總了PHP中kArray::array_is_associative方法的典型用法代碼示例。如果您正苦於以下問題:PHP kArray::array_is_associative方法的具體用法?PHP kArray::array_is_associative怎麽用?PHP kArray::array_is_associative使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kArray
的用法示例。
在下文中一共展示了kArray::array_is_associative方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array2xmlImpl
protected function array2xmlImpl($array, $num_prefix = "num_", $depth = 0)
{
$depth++;
// echo ( "[$depth]array2xmlImpl:" . print_r ( $array , true ) . "<br>");
// echo ( "[$depth]--array2xmlImpl: $num_prefix <br>");
$result = "";
if ($array instanceof myBaseObject) {
/*
* $obj = objectWrapperBase::toArrayImpl ( $array );
$result.= self::array2xmlImpl( $array, $num_prefix , $depth);
*/
$result = null;
$fields = $array->getFieldNames();
foreach ($fields as $key) {
if (empty($key)) {
continue;
}
$val = $array->get($key);
// TODO - think if want to compare to === null -
// this will return 0 and empty strings (doesn't happen now)
//if ( empty ( $val ) && ( $val !== 0 ) ) continue;
if (!self::shouldDisplayValue($val)) {
continue;
}
try {
$key = self::tagNameFromField($key, $num_prefix);
// fix key if needed
$result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
} catch (Exception $ex) {
$result .= "<" . $key . ">ERROR</" . $key . ">";
}
}
} else {
if ($array instanceof objectWrapperBase) {
/*
$obj = $array->toArray();
$result.= self::array2xmlImpl( $array, $num_prefix , $depth);
*/
$result = "";
$fields = $array->getFieldNames();
$i = 0;
foreach ($fields as $key) {
if (empty($key)) {
continue;
}
$val = $array->get($key);
if (!self::shouldDisplayValue($val)) {
continue;
}
try {
$key = self::tagNameFromField($key, $num_prefix);
// fix key if needed
$result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
} catch (Exception $ex) {
$result .= "<" . $key . ">ERROR</" . $key . ">";
}
}
} elseif (is_array($array)) {
$result = "";
if (kArray::array_is_associative($array)) {
foreach ($array as $key => $val) {
try {
$key = self::tagNameFromField($key, $num_prefix);
// fix key if needed
$result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
} catch (Exception $ex) {
$result .= "<" . $key . ">ERROR</" . $key . ">";
}
}
} else {
$array_size = count($array);
for ($i = 0; $i < $array_size; ++$i) {
if (key_exists($i, $array)) {
$val = $array[$i];
} else {
}
try {
$key = self::tagNameFromField($i, $num_prefix);
// fix key if needed
$result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
} catch (Exception $ex) {
$result .= "<" . $key . ">ERROR</" . $key . ">";
}
}
}
} elseif (is_object($array)) {
return "ERROR fromating object of type [" . get_class($array) . "]";
//echo ( "[$depth]array2xmlImpl:is_object " . get_class ( $array ) . "<br>" );
} else {
//cho ( "[$depth]array2xmlImpl: " . get_class ( $array ) . "<br>");
//return htmlentities ( $array );
if ($this->escape_text) {
// TODO - decide whether to encode or cdata or nothing - according to the name of the field
$escaped = kString::xmlEncode($array);
return $escaped;
/*
if ( $escaped != $array )
{
return "<![CDATA[$array]]>";
}
//.........這裏部分代碼省略.........