RE: [PHP] Printing a PHP Class

2002-07-31 Thread Jay Blanchard

[snip]
  My question is:
 How does one print out the Array?
[/snip]

Try print_r

http://www.php.net/manual/en/function.print-r.php

HTH!

Jay

I took a pain pill, why are you still here? 

***
* *
* Texas PHP Developers Meeting*
* Spring 2003 *
* T Bar M Resort  Conference Center  *
* New Braunfels, Texas*
* Interested? Contact;*
* [EMAIL PROTECTED] *
* *
***


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Printing a PHP Class

2002-07-31 Thread 1LT John W. Holmes

Use is_array() to see if it's an array. If it is, then loop through it and
display the contents...

---John Holmes...

- Original Message -
From: Marty McGowan [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, July 31, 2002 4:15 PM
Subject: [PHP] Printing a PHP Class


 PHPers,
 In a genaology application, where I add individuals to
 an array:

  $everyone[] = new Individual($id);

 I'd like to print the indiviuals' attributes.  Some of these are
 in array's themselves: like a list of event's in one's life.

 My problem is:
 when printing the Class Variables using the standard approach:
 =
 function print_vars($obj) {
 $arr = get_object_vars($obj);
 while (list($prop, $val) = each($arr))
 {
echo $prop\t$val\n;
 }
 }
 =
 I see the message:

  Variables: Person: Added RELI attribute

 id I6
 last McGOWAN
 first Martin James
 suffix Sr.

 sex M

 lifeevent Array
 attribute Array
 

   My question is:
  How does one print out the Array?

   My attempt at testing .

(strcmp($val,Array) == 0)

   was fruitless, as the print value of
  $var is always a string, but not always
  in other contexts.

   What am I missing?

 Thanks,
  -- Marty McGowan




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Printing a PHP Class

2002-07-31 Thread 1LT John W. Holmes

Maybe code will help...

 My problem is:
 when printing the Class Variables using the standard approach:
 =
 function print_vars($obj) {
 $arr = get_object_vars($obj);
 while (list($prop, $val) = each($arr))
 {
echo $prop\t$val\n;
 }
 }
 =

Try this:

function print_vars($obj) 
{
   $arr = get_object_vars($obj);
   while (list($prop, $val) = each($arr))
  {
if(is_array($val))
{ echo $prop\t . implode(,,$val) . \n; }
else
{ echo $prop\t$val\n; } 
  }
}

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Printing a PHP Class

2002-07-31 Thread Jerome Houston

Also, you could use print_r($obj);
to look at everything in the class, with arrays already expanded for you.


http://www.php.net/manual/en/function.print-r.php

jerome

From: Marty McGowan [EMAIL PROTECTED]

PHPers,
   In a genaology application, where I add individuals to
an array:

  $everyone[] = new Individual($id);

I'd like to print the indiviuals' attributes.  Some of these are
in array's themselves: like a list of event's in one's life.

My problem is:
when printing the Class Variables using the standard approach:
=
function print_vars($obj) {
 $arr = get_object_vars($obj);
 while (list($prop, $val) = each($arr))
   {
   echo $prop\t$val\n;
   }
}
=
I see the message:

  Variables: Person: Added RELI attribute

id I6
last McGOWAN
first Martin James
suffix Sr.

sex M

lifeevent Array
attribute Array


   My question is:
  How does one print out the Array?

   My attempt at testing .

(strcmp($val,Array) == 0)

   was fruitless, as the print value of
  $var is always a string, but not always
  in other contexts.

   What am I missing?

Thanks,
  -- Marty McGowan




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




_
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php