php - using yield to return an array of data -


i never used generators in php. understand way use : foreach array tasks each value greping specific line big file remove caracteres..

what need :

i need retrieve bands dabatase. sure have 'limit' argument don't exceed php's memory (there're 30 000 bands..). have filters values , return new array client rest api.

what want know :

is interesting me create method trait called 'generator' perform code bellow ?

in cases, have create new array return method

    $bands = models\bands::find($bandsparameters);     $json  = [];      foreach ($bands $band) {         $followers    = $band->getfollowers();         $followersarr = [];          foreach ($followers $follower) {             $followerimage = $follower->getimage();             $followerobj   = (object)[                 'id'        => $follower->id,                 'username'  => $follower->username,                 'image'     => $followerimage->url,                 'online'    => $follower->online,                 'createdon' => $follower->createdon,                 'updatedon' => $follower->updatedon,                 'lastlogin' => $follower->lastlogin,             ];             $followersarr[] = $followerobj;         }          $info    = $band->getinfo($bandinfoparameters)->getfirst();         $bandobj = (object)[             'id'         => $band->id,             'name'       => $band->name,             'style'      => $band->styles,             'country'    => $band->country,             'summary'    => isset($info->summary) ? $info->summary : null,             'followers'  => $followersarr,             'createdon'  => $band->createdon,             'updatedon'  => $band->updatedon,             'authoredby' => $band->authoredby,             'updatedby'  => $band->updatedby,         ];          $json[] = $bandobj;     }      return ['key' => 'bands', 'value' => $json]; 


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -