Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   Frameworks y PHP orientado a objetos (http://www.forosdelweb.com/f68/)
-   -   obtener elemento de un array (http://www.forosdelweb.com/f68/obtener-elemento-array-577389/)

SidP 18/04/2008 09:31

obtener elemento de un array
 
hola comunidad
no tengo claro como podria hacerlo..
tengo estas funciones
Código:

public function bindList(){
  $stu_num=$_GET['id'];
  return $this->_studentDetails=    StudentPeer::doSelectStudentDetails($stu_num));
  }

la otra funcion en la clase StudentPeer
Código:

public function doSelectStudentDetails($stu_num){
  return StudentRecord::finder()->findAllBystu_num($stu_num); //retorna un array de objetos
}

es decir en mi caso me retorna esto este array
Código:

StudentRecord Object ( [stu_num] => 470029898 [stu_fname] => test [stu_lname] => test [stu_email] => [email protected] [stu_username] => tes [stu_birthdate] => 2007-04-18 00:00:00 [stu_phone] => [stu_sex] => F [stu_province_code] => 21 [group_num] => 108 [stu_municipality] => xxxx[stu_password] => e10adc3949ba59abbe56e057f20f88 [stu_active] => 1 [stu_number] => 18 [_readOnly:private] => [_connection:private] => TDbConnection Object ( [_dsn:private] => mysql:host=localhost;dbname=proyecto [_username:private] => root [_password:private] => nightwish [_attributes:private] => Array ( ) [_active:private] => 1 [_pdo:private] => PDO Object ( ) [_e:private] => Array ( ) ) [_e:private] => Array ( ) )
como podria sacar los datos por ejemplo del campo stu_lname

gracias de antemano

GatorV 18/04/2008 12:58

Re: obtener elemento de un array
 
Hola SidP,

En el código que expones, lo que te regresa es un objeto, no un arreglo, podrías accesar así:
Código PHP:

echo $result->stu_lname

Saludos.

SidP 18/04/2008 13:33

Re: obtener elemento de un array
 
hola GatorV y gracias por responder.....
mira lo que tengo
Código:

object(StudentRecord)#119 (17) { ["stu_num"]=>  string(9) "470029898" ["stu_fname"]=>  string(4) "test" ["stu_lname"]=>  string(4) "test" ["stu_email"]=>  string(22) "[email protected]" ["stu_username"]=>  string(3) "tes" ["stu_birthdate"]=>  string(19) "2007-04-18 00:00:00" ["stu_phone"]=>  NULL ["stu_sex"]=>  string(1) "F" ["stu_province_code"]=>  string(2) "21" ["group_num"]=>  string(3) "108" ["stu_municipality"]=>  string(7) "Jiguani" ["stu_password"]=>  string(30) "e10adc3949ba59abbe56e057f20f88" ["stu_active"]=>  string(1) "1" ["stu_number"]=>  string(2) "18" ["_readOnly:private"]=>  bool(false) ["_connection:private"]=>  object(TDbConnection)#27 (7) { ["_dsn:private"]=>  string(36) "mysql:host=localhost;dbname=proyecto" ["_username:private"]=>  string(4) "root" ["_password:private"]=>  string(9) "xxxxx" ["_attributes:private"]=>  array(0) { } ["_active:private"]=>  bool(true) ["_pdo:private"]=>  object(PDO)#79 (0) { } ["_e:private"]=>  array(0) { } } ["_e:private"]=>  array(0) { } }
si lo hago de esa forma lo que obtengo es esto
Código:

[Notice] Trying to get property of non-object
ahora si lo hago de esta forma
Código:


print_r($this->_studentDetails[0]->stu_lname) ahora si me va bien

...solo tenia que agregarle el subindice.

Muchisimas Gracias :adios:


La zona horaria es GMT -6. Ahora son las 06:13.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.