Just for the record, when you return, you
return.
The function returns the value and ends when you return, no if ands or buts! Therefor you can only return once in a function.
In PHP 5, I believe "var" is being deprecated, use
public and
private to declare variables:
PHP Code:
class MyClass
{
public $foo = 'bar';
private $bar = 'foo';
}
Secondly, take caution with echo and print, try not to use them like you did, one after another.. it's more logical to use it like such:
PHP Code:
function get_post()
{
echo $var1 . $var 2;
// personal I wouldn't use a function to return something that's public
}
Thirdly, you don't need a function to return variables (that is, if they're not
private)
PHP Code:
print $object->var1;
Edit
Yes, there is an easier way, use arrays:
PHP Code:
class MyClass
{
public $data = array( );
public function data_to_array( $result )
{
while( $data = mysql_fetch_array( $result ) )
{
$this->data[] = $data;
}
}
}
print_r( $object->data ); // look at how the array is structured
// when you figure the structure out, you can then access the array like:
print $object->data['foo'];
