array ​
File: src/Helpers/array.php
Array manipulation helpers used throughout Modularous for merging, exporting, and transforming PHP arrays.
Functions ​
array_merge_recursive_distinct ​
array_merge_recursive_distinct(array &$array1, array &$array2): arrayDeep-merges two arrays. When the same key exists in both arrays and both values are arrays, it recurses. Otherwise the value from $array2 overwrites $array1.
Unlike PHP's array_merge_recursive, this does not create sub-arrays for scalar key conflicts.
array_merge_recursive_preserve ​
array_merge_recursive_preserve(array ...$arrays): arrayVariadic deep merge. Calls array_merge_recursive_distinct across all provided arrays in order. Used as the standard deep-merge utility across Modularous controllers and config helpers.
array_export ​
array_export(array $array, string $indent = ''): stringConverts an array to a formatted PHP array(...) string suitable for writing to a .php config file. Recursively indents nested arrays.
php_array_file_content ​
php_array_file_content(array $array): stringWraps array_export() output in a full PHP file template:
<?php
return array_export($array);Used by code generators that write config files.
array_to_object ​
array_to_object(array $array): objectRecursively converts an associative array to a stdClass object tree using json_decode(json_encode($array)).
object_to_array ​
object_to_array(object $object): arrayRecursively converts a stdClass object tree back to an associative array.
nested_array_merge ​
nested_array_merge(array $array1, array $array2): arrayAlias for array_merge_recursive_distinct — accepts both arrays by value.
array_merge_conditional ​
array_merge_conditional(array $base, array $conditional, bool $condition): arrayIf $condition is true, merges $conditional into $base using array_merge_recursive_distinct. Otherwise returns $base unchanged.
change_array_file_array ​
change_array_file_array(string $filePath, string $key, mixed $value): voidReads a PHP array config file, sets $key to $value using Arr::set(), then writes the updated array back to the file using php_array_file_content().
add_route_to_config ​
add_route_to_config(string $filePath, string $routeName, array $routeConfig): voidLoads a route config file and appends $routeConfig under routes.$routeName. Uses change_array_file_array internally.
array_except ​
array_except(array $array, array|string $keys): arrayReturns a copy of $array with the given $keys removed. Thin wrapper over Arr::except().