Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print_r and objects within arrays

Status
Not open for further replies.

LaundroMat

Programmer
Dec 2, 2003
67
BE
Hi all,

Suppose I have this object, form:
Code:
form Object
(
    [form] => Array
        (
            [0] => <form action=&quot;formtest.php&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;>

        )

    [url] => formtest.php
    [method] => POST
    [enctype] => multipart/form-data
    [element] => Array
        (
            [0] => Object
        )

)
How do I print out the object that's embedded in the [element]? I tried:
Code:
print_r ($form->element[0]);
and others, but none worked... Anyone?
 
I don't know.

Using the following code to set up the object:

[code<?php

class foo
{
var $foo;

function foo()
{
$this->foo = 'foo';
}
}

class bar
{
var $bar;

function bar()
{
$this->bar = 'bar';
}
}

class form
{
var $element;

function form ()
{
$this->element = array
(
new foo(),
new bar()
);
}
}


$form = new form();


print_r ($form->element[0]);

?>
[/code]


Correctly outputs:
Code:
foo Object
(
    [foo] => foo
)


What version of PHP are you running?



Want the best answers? Ask the best questions: TANSTAAFL!!
 
Gnnh. My fault completely... I tried your code, and ofcourse it all worked fine.
Then I wondered, but how do I add objects to that array? And everything fell in place then. In a function, I used:
Code:
$this->element[] .= new $foo();
Watch that dot! I never should have used it, and that's why it always went wrong.

Thanks for the reply, it pointed me in the right direction :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top