viernes, 5 de agosto de 2016

Arreglos de objetos en PHP

Hola amigos aqui les comparto un ejemplo de como guardar objtetos en un arreglo en PHP, en este ejemplo guardaremos estudiantes su nombre y matricula.
nombre = $nom;
  $this->matricula = $mat;
 }
 public function Agregar(Alumno $al)
 {
       $this->objAlumno[$this->indice] = $al;
       $this->indice++;
 }

 public function getNombre()
 {
  return $this->nombre;
 }
    
 public function getMatricula()
 {
  return $this->matricula;
 }

 public function Mostrar()
 {
  foreach ($this->objAlumno as $item)
  {
   echo "Nombre: ".$item->getNombre()."
"; echo "Matricula: ".$item->getMatricula()."
"; } } } //$nombre = $_POST['nombre']; //$matricula = $_POST['matricula']; //$obj1 = new Alumno($nombre,$matricula); //$obj1->Agregar($obj1); //$obj1->Mostrar(); $obj1 = new Alumno("Misael Alanis","12121212"); $obj2 = new Alumno("Luar Alanis","10101010"); $obj1->Agregar($obj1); $obj1->Agregar($obj2); $obj1->Mostrar(); ?>

Ejemplo
Dejar un comentario.

No hay comentarios:

Publicar un comentario