yiisoft/yii2 · error · InvalidArgumentException
Argument $array must be an array or implement Traversable
Error message
Argument $array must be an array or implement Traversable
What it means
Error "Argument $array must be an array or implement Traversable" thrown in yiisoft/yii2.
Source
Thrown at framework/helpers/BaseArrayHelper.php:1084
* // [
* // 'A.0' => 1
* // 'A.1' => 2
* // 'B.C' => 1
* // 'B.D' => 2
* // 'E' => 1
* // ]
* ```
*
* @param array $array the input array to be flattened in terms of name-value pairs.
* @param string $separator the separator to use between keys. Defaults to '.'.
*
* @return array the flattened array.
* @throws InvalidArgumentException if `$array` is neither traversable nor an array.
*/
public static function flatten($array, $separator = '.'): array
{
if (!static::isTraversable($array)) {
throw new InvalidArgumentException('Argument $array must be an array or implement Traversable');
}
$result = [];
foreach ($array as $key => $value) {
$newKey = $key;
if (is_array($value)) {
$flattenedArray = self::flatten($value, $separator);
foreach ($flattenedArray as $subKey => $subValue) {
$result[$newKey . $separator . $subKey] = $subValue;
}
} else {
$result[$newKey] = $value;
}
}
return $result;
}View on GitHub (pinned to 66f00d18a2)
When it happens
Trigger: Thrown at framework/helpers/BaseArrayHelper.php:1084 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/b592f77fe17e0c58.
Report an issue: GitHub.