atholon Posted January 2, 2009 Share Posted January 2, 2009 I am looking to pass an array of constants to a funtion, is there a way to do that without declaring an array like $myArray = array(); I want to just pass it directly to the method. Like myMethod([ELEMENT1,ELEMENT2]) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 <?php some_method_call(array(SOME_CONSTANT, ANOTHER_ONE, GOSH_THIS_IS_FUN)); ?> Quote Link to comment Share on other sites More sharing options...
atholon Posted January 2, 2009 Author Share Posted January 2, 2009 k so basically the same, thx Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 All i can think off function or a define. <?php function show_a(){ $a=array("hi ","there"," im"," redarrow"); foreach ($a as $b){ echo $b; } } function show_b(){ $a=array("i"," love"," php"); foreach ($a as $b){ echo $b; } } show_a(); echo"<br>"; show_b(); define("NAME","i am redarrow"); define("PROGRAMMING","i love php programming"); $a=array(NAME,PROGRAMMING); echo " <br> <br> $a[0] <br> $a[1]"; ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted January 2, 2009 Share Posted January 2, 2009 if these constants are defined... define('SOME_CONSTANT' , 36); then these would be in the global scope and available any where in your code... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.