本文整理汇总了PHP中ArrayHelper::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::toArray方法的具体用法?PHP ArrayHelper::toArray怎么用?PHP ArrayHelper::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::toArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(array $data = NULL, $keyColumnNames = NULL, $columnPrefix = NULL, $columnSuffix = NULL)
{
parent::__construct();
$this->keyColumnNames = ArrayHelper::toArray($keyColumnNames);
$this->columnPrefix = $columnPrefix;
$this->columnSuffix = $columnSuffix;
$this->data = $data;
}
示例2: toArray
public static function toArray($object, $recursive = true)
{
if (is_array($object)) {
$res = [];
foreach ($object as $key => $each) {
if (is_array($each) || is_object($each)) {
$res[$key] = ArrayHelper::toArray($each, $recursive);
} else {
$res[$key] = $each;
}
}
return $res;
}
if (!is_object($object)) {
return [$object];
}
if ($object instanceof stdClass) {
return (array) $object;
}
$res = [];
$reflectionClass = new \ReflectionClass($object);
$properties = $reflectionClass->getProperties();
foreach ($properties as $prop) {
/* @var $prop ReflectionProperty */
$name = $prop->getName();
if ($name[0] == "_") {
continue;
}
$getter = "get" . ucfirst(lcfirst(strtr(ucwords(strtr($name, ['_' => ' '])), [' ' => ''])));
if (is_callable([$object, $getter])) {
$getter_value = $object->{$getter}();
if ($recursive && (is_array($getter_value) || is_object($getter_value))) {
$res[$name] = ArrayHelper::toArray($getter_value, $recursive);
} else {
$res[$name] = $getter_value;
}
}
}
return $res;
}