本文整理汇总了PHP中Arr::isAssoc方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::isAssoc方法的具体用法?PHP Arr::isAssoc怎么用?PHP Arr::isAssoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::isAssoc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toCsv
/**
* To CSV conversion
*
* @param mixed $data
* @param mixed $delimiter
* @return string
*/
public function toCsv($data = null, $delimiter = null)
{
// csv format settings
$newline = Arr::get($this->config, 'csv.newline', "\n");
$delimiter or $delimiter = Arr::get($this->config, 'csv.delimiter', ',');
$enclosure = Arr::get($this->config, 'csv.enclosure', '"');
$escape = Arr::get($this->config, 'csv.escape', '\\');
// escape function
$escaper = function ($items) use($enclosure, $escape) {
return array_map(function ($item) use($enclosure, $escape) {
return str_replace($enclosure, $escape . $enclosure, $item);
}, $items);
};
if ($data === null) {
$data = $this->data;
}
if (is_object($data) and !$data instanceof \Iterator) {
$data = $this->toArray($data);
}
// Multi-dimensional array
if (is_array($data) and Arr::isMulti($data)) {
$data = array_values($data);
if (Arr::isAssoc($data[0])) {
$headings = array_keys($data[0]);
} else {
$headings = array_shift($data);
}
} else {
$headings = array_keys((array) $data);
$data = array($data);
}
$output = $enclosure . implode($enclosure . $delimiter . $enclosure, $escaper($headings)) . $enclosure . $newline;
foreach ($data as $row) {
$output .= $enclosure . implode($enclosure . $delimiter . $enclosure, $escaper((array) $row)) . $enclosure . $newline;
}
return rtrim($output, $newline);
}
示例2: merge
/**
* Recursively merge two or more arrays. Values in an associative array
* overwrite previous values with the same key. Values in an indexed array
* are appended, but only when they do not already exist in the result.
*
* Note that this does not work the same as [array_merge_recursive](http://php.net/array_merge_recursive)!
*
* $john = array('name' => 'john', 'children' => array('fred', 'paul', 'sally', 'jane'));
* $mary = array('name' => 'mary', 'children' => array('jane'));
*
* // John and Mary are married, merge them together
* $john = Arr::merge($john, $mary);
*
* // The output of $john will now be:
* array('name' => 'mary', 'children' => array('fred', 'paul', 'sally', 'jane'))
*
* @param array $array1 initial array
* @param array $array2,... array to merge
* @return array
*/
public static function merge($array1, $array2)
{
if (Arr::isAssoc($array2)) {
foreach ($array2 as $key => $value) {
if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
$array1[$key] = self::merge($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
} else {
foreach ($array2 as $value) {
if (!in_array($value, $array1, true)) {
$array1[] = $value;
}
}
}
if (func_num_args() > 2) {
foreach (array_slice(func_get_args(), 2) as $array2) {
if (self::isAssoc($array2)) {
foreach ($array2 as $key => $value) {
if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
$array1[$key] = self::merge($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
} else {
foreach ($array2 as $value) {
if (!in_array($value, $array1, true)) {
$array1[] = $value;
}
}
}
}
}
return $array1;
}
示例3: recursiveToStdClass
/**
* @param mixed $val
* @return object
*/
protected static function recursiveToStdClass($val)
{
if (is_array($val)) {
if (!Arr::isAssoc($val)) {
return $val;
}
return (object) array_map(array('\\CIC\\Cicbase\\Utility\\Arr', 'recursiveToStdClass'), $val);
} else {
return $val;
}
}