Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.