Search
 
SCRIPT & CODE EXAMPLE
 

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 :: display page template using functions.php 
Php :: hook de pré-commit se déclenche 
Php :: ipay generate hash id 
Php :: what is the mixmam size that php can take 
Php :: laravel model where set fields laravel 
Php :: Laravel - How to create custom configuration variables and access 
Php :: executer page php via boutton 
Php :: List all controllers in codeigniter HMVC structure 
Php :: magento2 join table with prefix 
Php :: laravel api routes 
Php :: PHP stripslashes — Un-quotes a quoted string 
Php :: Laravel Mix npm run production error 
Php :: laravel General error: 1215 Cannot add foreign key constraint" 
Php :: unlink() in php 
Php :: Expected response code 250 but got code "530", with message "530 Must issue a STARTTLS command first. " 
Php :: scheduling in laravel in custom cron 
Php :: random String Function PHP 
Php :: laravel except route 
Php :: Paginating API HTTP Response in Laravel 
Php :: image not displaying in laravel 
Php :: progress bar calculate percentage php 
Php :: remove column laravel migration 
Java :: import java math 
Java :: how to play sounds on java 
Java :: properties java 8 maven in pom xml 
Java :: java age from date 
Java :: full screen android java 
Java :: dialog getWindow().setBackgroundDrawable transparent 
Java :: java format 2 decimal places 
Java :: random string method java 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =