|
Posted by Johnny on 09/25/06 18:14
"The87Boy" <the87boy@gmail.com> wrote in message
news:1159199042.142987.271750@i3g2000cwc.googlegroups.com...
> Is there any ways to make a function like system(), which returns more
> than one value (true or false) and (the array)
>
It is something I've done many times in c++ but not so much in PHP...
that one thing returned could be an object which has whatever you want in
it.
here is the relevant line from the docs
http://us2.php.net/manual/en/functions.returning-values.php
" Values are returned by using the optional return statement. Any type may
be returned, including lists and objects."
here is a quick example:
<?php
class stuff { # a container for all your stuff
var $the_bool;
var $the_array;
function stuff($b,$a) {
$this->the_bool = $b;
$this->the_array = $a;
}
function get_bool () {
return $this->the_bool;
}
function get_array () {
return $this->the_array;
}
}
$a[] = "bread";
$a[] = "butter";
$a[] = "salt";
var_dump($a);
echo "<br/>var dump thing :<br />";
$thing = new stuff(true,$a);
var_dump($thing);
echo "<br />the bool is ".$thing->get_bool();
$a1 = $thing->get_array();
echo "<br/>var dump a1 is<br />";
var_dump($a1);
echo "<br />the array 0 is ".$a1[0];
echo "<br />the array 1 is ".$a1[1];
echo "<br />the array 2 is ".$a1[2];
$arr[] = "49";
$arr[] = "sugar";
$arr[] = "37.294";
function demo($bl,$ar) {
$c = new stuff($bl,$ar);
return $c;
}
$d = demo(true,$arr);
echo "<br/><br/>d->bool returned from demo is ".$d->get_bool();
$da = $d->get_array();
echo "<br/>d->a[0] returned from demo is ".$da[0];
echo "<br/>d->a[1] returned from demo is ".$da[1];
echo "<br/>d->a[2] returned from demo is ".$da[2];
?>
[Back to original message]
|