php - empty array outside function and array is ok inisde -


i'm having problems getting array values outside function , file. inside array , function have this, values defined getters , setters

array ( [0] => xxxxxxxxxx [1] => 5Âșa ) 

those values defined setters , working since have values print_r

 public function getturmaeprofessor(){     global $myarr;     $myarr[] = $this->getprofessor();     $myarr[] = $this->getturma();     print_r($myarr);     return $myarr; } 

now file use this

$dados = $esmaior->getturmaeprofessor(); if(!$dados){     echo "sem dados"; } print_r($dados); 

and result empty, array empty...why??

thanks

update function called here

$this->setturma($nome_turma);         $this->setprofessor(($nome_professor));         $this->getturmaeprofessor(); 

so if put this

public function getturmaeprofessor(array $myarr) 

i'm gonna need change call method...how it??

update 2

ok... let me put maybe it's better understand. main function one

    public function novaaula($atividade, $turmas, $local, $dataaula, $inicio, $fim, $fundamentacao, $observacoes, $id_professor){     try{     $stmt = $this->db->prepare("insert `aulas_exterior` (`atividade`,`id_turma`,`local`,`data_aula`,`inicio`,`fim`,`fundamentacao`,`observacoes`)                                  values (:atividade,:id_turma,:local,:data_aula,:inicio,:fim,:fundamentacao,:observacoes);");     $stmt->bindparam(":atividade", $atividade);     $stmt->bindparam(":local", $local);     $stmt->bindparam(":data_aula", $dataaula);     $stmt->bindparam(":inicio", $inicio);     $stmt->bindparam(":fim", $fim);     $stmt->bindparam(":fundamentacao", $fundamentacao);     $stmt->bindparam(":observacoes", $observacoes);     $turma = explode(',', $turmas);     foreach ($turma $id_turma) {         $stmt->bindparam(':id_turma', $id_turma, pdo::param_int);         $result = $stmt->execute();         $idaula = $this->db->lastinsertid();         $this->insertpedidobylastid($idaula,$id_professor, $id_turma);         $nome_turma = $this->getturmabyid($id_turma);         $nome_professor = $this->getnomebyid($id_professor);         $this->setturma($nome_turma);         $this->setprofessor(($nome_professor));         $this->getturmaeprofessor();     }     if (!$result) {         print_r($stmt->errorinfo());         return array('status' => 'error', 'message' => 'problema ao gravar esta nova atividade...');     }     else{         return array('status' => 'success', 'message' => 'o pedido foi criado com sucesso...');     } } catch (exception $ex) {     echo $ex->getmessage();     } } 

and can see i'm setting these 2

 $this->setturma($nome_turma);         $this->setprofessor(($nome_professor)); 

and call method

$this->getturmaeprofessor(); 

entering function want have names 2 setters

 public function getturmaeprofessor(array $myarr){     $myarr[] = $this->getprofessor();     $myarr[] = $this->getturma();     return $myarr; } 

until now...everything working....the problem when i'm trying return in other file...i receive empt...why??

do not use global. fix function accept arguments:

 public function getturmaeprofessor(array $myarr){     // remove global $myarr;      ....      return $myarr; } 

optionally (but not recommend unless know want go way) pass array reference:

 public function getturmaeprofessor(array &$myarr){     // remove global $myarr;      // no return time needed } 

now, since getturmaeprofessor() requires argument must change invocations that, i.e.

$dados = $esmaior->getturmaeprofessor($myarr); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -