Help with more complex PHP function

Join Discord

Far

tsniffer
Staff member
Developer
May 19, 2003
20,179
30
2,783
540
Im trying to get three functions in to one to mimize the coding, i'm doing this by using a switch. but for some reason its not working, and is outputting all 4 cases at the same time.

I'm calling the function 3 times on my page, each time im putting a different number so it should choose a different case.

But it just outputs "onetwothreefour" and doesn't output $i at all.

PHP:
	filefinder('includes/tutorials',1);
	filefinder('includes/tutorials',2);
	filefinder('includes/tutorials',3);

PHP:
function filefinder($tdir,$i)
{
$adr = $_GET["id"];
$ext = '.php';
$adrext = $adr . $ext;

        $dirs = scandir($tdir);
        foreach($dirs as $file)
        {
                if (($file == '.')||($file == '..'))
                {
                }
                elseif (is_dir($tdir.'/'.$file))
                {
                        filefinder($tdir.'/'.$file);
                }

		if ($file == $adrext)
		{
		switch ($i) {
    			case 0:
				echo $i; echo "one";
    			case 1:
				echo $i; echo "two";
    			case 2:
				echo $i; echo "three";	
			case 3:
				echo $i; echo "four";
			}
		}
        }
}
 

thebigguy

Dedicated Member
Dedicated Member
Apr 16, 2003
115
0
113
Blackburn
If you havent already fixed this.

Depending on what you are doing you need to add some extra info into the code.

You would need to add some code in echo for new lines or space etc. Also add a hyperlink to each tutorial

Will upload some code i have done to try and help if you like but that will be later on