Jump to content

what am I doing wrong with this function


devWhiz

Recommended Posts

<?php
$a = array(3, 4, 18, 15);
$b = array(12, 10, 11, 24);
$c = array(5, 6);
$d = array(7, 8, 13);
$e = array(19, 16);

function test($ID)
{
	if(in_array($ID, $a))
	{ echo "a"; }
	if(in_array($ID, $b))
	{ echo "b"; }
	if(in_array($ID, $c))
	{ echo "c"; }
	if(in_array($ID, $d))
	{ echo "d"; }
	if(in_array($ID, $e))
	{ echo "e"; }	
}

$test = 3;

test($test);
?>

 

Why doesn't that echo "a"

 

I don't really get what I am doing wrong, any help is appreciated

Globals is never the fix, and should be depreciated IMHO.

 

Either build the arrays inside the function, or pass them as arguments.  Setting Globals defeats the purpose of a function, as you have now tied the function to a specific instance, and can no longer use the function, if one of the globals doesn't exist in the script.

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.