php - Assoc. Array, get Element with special id -


i have assoc array alldept. want 'name' element array id e.g. '1';

how access id , output 'name'?

the id saved in $result[$i]['abteilung']

thank much!

$manager = $this->getdoctrine()                 ->getmanager('olddb')                 ->getrepository('chrisolduserbundle:bpdepartment'); $dept = $manager->findby([],['name' => 'asc']); $alldept = array(); foreach ($dept $singledpt){     $alldept[] = array("id" => $singledpt->getid(),                         "name" => $singledpt->getname()                       );  } 

as building array seem sensible build in way later usable.

so why not build array this

$manager = $this->getdoctrine()                 ->getmanager('olddb')                 ->getrepository('chrisolduserbundle:bpdepartment'); $dept = $manager->findby([],['name' => 'asc']); $alldept = array(); foreach ($dept $singledpt) {     $alldept[ $singledpt->getid() ] = $singledpt->getname(); } 

now if know want name of dept = 1

echo $alldept[1]; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -