Jump to content

[SOLVED] Function Question?


networkthis

Recommended Posts

How can I compare the output from this function with a set variable....example this fucntion is counting the number of folders I have in a current said directory.  I need to have the output when the directory count is zero to not allow an auto filled drop down menu to be populated as empty.  I already have all code finished for this and to autofill the drop menu.  So, what I am having problems with is taking the output of this function and comparing it 0

 

 

Here is what I currently have...

 

<?php

$Number_of_Folders = displayFolderCount($path); 
if ($Number_of_Folders== '0'){
    //Then do nothing....
    }

?>

 

How do I pull the value from the function and change it to a variable???????? Thought this would work but it doesn't........any ideas??

<?php 

$Number_of_Folders = displayFolderCount($path); 

?>

 

example of my count folder function......

 

<?php 

function displayFolderCount($path)
{
$dir = opendir($path); 

while(FALSE !== ($file = readdir($dir)))
{     	

if ($file != "." && $file != "..")   

{       

$files[] = "$file";    }} closedir($dir);

$foldercount=0;
foreach($files as $value){ 
             # Fname will be used to simply copy the Actual Name of the File!!!
$fName = $value;

			# Create the path for the file
			$value = $path.'/'.$value;				

#****************************#
# Simply checks to see if the $file is     #
# actually a DIRECTORY.  If it is display #
# the following.                                 #
#*****************************#

if (is_dir($value)) {
             $foldercount=$foldercount+1;
             }

}

echo $foldercount;	
}

?>

Link to comment
https://forums.phpfreaks.com/topic/124254-solved-function-question/
Share on other sites

Thanks for the quick responses.........the reason I have that long of a function is that I am having it not count folders hidden to the user...which are removed from the function...I left that part of the code out....

 

is it possible to use the glob count and to filter out specific folder names...as to not count them??? 

Thank you seriously for the help...sometimes its the little things!!!  it seems I had a typo in my if statement.  I had originally had a RETURN at the end of the function...but it would never work... so I changed it to echo to see if it was counting properly.  After you saying to use the RETURN I got to looking at the rest of the code.  Come to find out this does not work

 

<?php

if ($Number_of_Folders = '0'){
    //Then do nothing....
    }

?>

 

this does!

 

<?php
if($Number_of_Folders == 0 {
   //Then do nothing....
   }
?>

 

Once again thank you and happy coding!!

Remember that = is not the same as == (or even ===).

 

=

 

http://au.php.net/manual/en/language.operators.assignment.php

 

 

== and ===

 

http://au.php.net/manual/en/language.operators.comparison.php

 

//This won't work - as you stated

if ($Number_of_Folders = '0'){
    //Then do nothing....
    }

//This will - as you stated

if ($Number_of_Folders == 0){
    //Then do nothing....
    }

//This will too!

if ($Number_of_Folders == '0'){
    //Then do nothing....
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.