Get array value from other function
Posted: Wed Mar 09, 2005 6:44 pm
I have two function which the first function for read file and the second for view
I want to print the value of array from readFile(), i have tried with the same function and it's no problem, in the same function i just use the for statement to print name, coment and space.
But i want to separate my function, and i don't know how to call the name, comment and space in view function. I use
may be i am wrong because there no meaning for this statement
feyd | hey look ma,
Code: Select all
function readFile(){
$fd = fopen("guest.dat","r");
$i=0;
while(!feof($fd)){
$i++;
$name[] = trim(fgets($fd),255);
$comment[] = trim(fgets($fd),255);
$space[] = trim(fgets($fd),255);
}
fclose($fd);
}
function view(){
global $HTTP_GET_VARS;
$pageLength = 5;
$this->readFile();
if(isset($HTTP_GET_VARS["start"]) && is_numeric($HTTP_GET_VARS["start"])){
$mulai = $HTTP_GET_VARS["start"];
}else{
$start = 0;
}
for($i=$start; $i<$start+$pageLength&& $i<$this->readFile();$i++){
//Want to print the array from readFile
}
}But i want to separate my function, and i don't know how to call the name, comment and space in view function. I use
Code: Select all
echo $this->readFile().name[$i];feyd | hey look ma,
Code: Select all
is on. [/color]