Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php recursive function to build array

function buildTree(array $elements, $parentId = 0) {
    $branch = array();

    foreach ($elements as $element) {
        if ($element['parent_id'] == $parentId) {
            $children = buildTree($elements, $element['id']);
            if ($children) {
                $element['children'] = $children;
            }
            $branch[] = $element;
        }
    }

    return $branch;
}

$tree = buildTree($rows);
Comment

PREVIOUS NEXT
Code Example
Php :: option selected in laravel blade 
Php :: php boolean to string 
Php :: php if else 
Php :: laravel folder permission 
Php :: program logic for second largest number in an array in php 
Php :: yii2 gridview filter exact value 
Php :: required_if laravel 
Php :: running a php project 
Php :: ile_put_contents(/opt/bitnami/apache2/htdocs/bootstrap/cache/services.php): failed to open stream: Permission denied 
Php :: wp_enqueue_script 
Php :: laravel assets path 
Php :: foreach skip current iteration 
Php :: full month name php 
Php :: Allowed memory size of 1610612736 bytes exhausted 4096 
Php :: laravel tree 
Php :: laravel passport get tokenId 
Php :: get day by date in php 
Php :: 0 
Php :: php do not refresh page after submit post 
Php :: php array loop 
Php :: download data from s3 and save to local disk laravel 
Php :: insert date of birth on the database using php 
Php :: php value to javascript variable laravel blade 
Php :: laravel 8 404 status 
Php :: advanced custom forms php 
Php :: how to make zip in php by multiple files 
Php :: install logger bundle in symfony project 
Php :: php split large text on line breaks into array 
Php :: Object of class IlluminateDatabaseEloquentBuilder could not be converted to string 
Php :: how to calculate percentage profile completion in laravel 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =