Computing.Net > Forums > Programming > PHP function problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

PHP function problem

Reply to Message Icon

Name: Phantom Sonic
Date: October 28, 2008 at 19:27:06 Pacific
OS: Windows Vista BASIC
CPU/Ram: 2.0 GB
Comment:

I'm trying to make a file system as a database and so far its all good put I have one problem.

I use:

function dfs_displayarray($input){
foreach($input as $whatever){
return $whatever;
}

}

to display everything in array.

say that I have 1,2, and 3 in $arrayvar.

Well I want my function the one above to display everything in that array but the problem is when I use return it will only display 1 not 1,2, or 3. If I use echo it displays 1,2, and 3 but when I try to use the strstr function it don't work right.

Can someone please help me out with this?

Thanks

PhantomSonic-We are all born with a destiny.Some of us know it and some of us are still searching for it.



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: October 28, 2008 at 22:04:48 Pacific
Reply:

you are returning from the function after you displayed the first item of the array.
if you want to return the whole array, then
use


return $arrayvar;

if you want to just display the array values
just using print


foreach($arr as $val){
print $val;
}

but put that outside your for loop.

if you want to return just the first item


return $array[0];


0

Response Number 2
Name: Phantom Sonic
Date: October 30, 2008 at 10:33:13 Pacific
Reply:

Well I made one function that gets the file contents and puts them into an array.

I'm trying to make another function that reads the array and out puts everything in that array.

And I'm trying to use strstr function to find some text from the function

If I store the function contents in a var like this

"$var=displayarray()"

now $var contains everything that displayarray has. Also If I change return to echo in the display array it will display everything in the array but then the strstr don't work.

$var could contain "This is my function"

and I use strstr to find function it will com back false.

This is also really hard to explain.

Also I'm going to post my function source code so you can see what I'm taking about.

function dfs_list($table,$value,$event){
error_reporting(0);
require"connect.php";
$array1=array();
$path1="$ydatabase/$table";
$openpth=opendir($path1);
//print"$path1";
while($listdir1=readdir($openpth)){

$mike="$path1/$dot1$listdir1/$value.dfs";
$test=str_replace(".","","$path1/$dot1$listdir1/$value").".dfs";
//print"$test
";
$fopen=fopen($test,'r');
while($fileval=fread($fopen,filesize("$test"))){
array_push($array1,"$fileval");
}

}

return $array1;
}


function dfs_displayarray($input){
foreach($input as $whatever){
return $whatever;
}

}


To use it you would need to have

$var=dfs_displayarray(dfs_list("Folder_that_the_files_are_in","Name_of_the_files",""));


also .dfs and dfs stands for Data for Sites


I really can't explain it any better then that so can someone please help me with this problem.

Also for the ones that already made a post to try to help me out with this thanks I really appreciate it

PhantomSonic-We are all born with a destiny.Some of us know it and some of us are still searching for it.


0

Response Number 3
Name: ghostdog
Date: October 30, 2008 at 19:36:45 Pacific
Reply:

the best way to describe your problem is to state down your specs. Provide sample inputs and describe desired output.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


java - parseInt To change a sheet by usin...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: PHP function problem

PHP search function www.computing.net/answers/programming/php-search-function/13314.html

problem understanding jscript www.computing.net/answers/programming/problem-understanding-jscript/5477.html

Passing pointers between functions www.computing.net/answers/programming/passing-pointers-between-functions/9083.html