Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php specific function to Unflatten array

/**
     * @param array|string $data Inserted data, like regular array, or simple string(will return as is)
     * @param string $separator string separator to know what we had.
     * @return array|string
     */
    public static function unFlatArr($data, $separator = '_')
    {
        $return = [];

        if (is_iterable($data)) {
            foreach ($data as $oldKey => $value) {
                $keysArr = explode($separator, $oldKey, 2);
                $key = $keysArr[0];
                $k = $keysArr[1] ?? null;

                if (null !== $k) {
                    //got nesting.
                    $value = self::unFlatAr([$k => $value], $separator);
                }
                $return[$key] = is_array($return[$key] ?? null) ? array_merge($return[$key], $value) : $value;
            }

        } else {
            $return = $data;
        }

        return $return;
    }
Comment

PREVIOUS NEXT
Code Example
Php :: laravel count 
Php :: laravel Error: Unsupported operand types: IlluminateDatabaseEloquentCollection - int 
Php :: How to download file with laravel 
Php :: order by array like sql php 
Php :: laravel eloquent get current sequence value 
Php :: how to check if coupons are valid or not magento 2 
Php :: php artisan reset --force 
Php :: eloquent complex queries 
Php :: tina4 create route 
Php :: getname eloquent slug laravel 
Php :: PHP stripos — Find the position of the first occurrence of a case-insensitive substring in a string 
Php :: Send Message from server laravel 
Php :: php double dollar not working in php version 8 
Php :: multidimensional session-array 
Php :: database interaction in codeigniter 
Php :: order table in laravel 
Php :: afiseaza id-ul sesiunii php 
Php :: required if null / require without laravel 
Php :: drupal 7 hook_node_insert 
Php :: laravel query with optional filter 
Php :: laravel convert array to string 
Php :: laravel allow null records relationship 
Php :: laravel make request 
Php :: get auth guard user laravel 
Php :: php print array key and value 
Php :: devilbox make database 
Php :: Get page title, excerpt or content by Name of the Page 
Php :: Downward half-Pyramid Pattern of Star 
Php :: magento 2 get layout create block with cache 
Php :: array.diff solution 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =