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]) Link to comment https://forums.phpfreaks.com/topic/139150-passing-an-array-to-a-method/ 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)); ?> Link to comment https://forums.phpfreaks.com/topic/139150-passing-an-array-to-a-method/#findComment-727771 Share on other sites More sharing options...
atholon Posted January 2, 2009 Author Share Posted January 2, 2009 k so basically the same, thx Link to comment https://forums.phpfreaks.com/topic/139150-passing-an-array-to-a-method/#findComment-727775 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]"; ?> Link to comment https://forums.phpfreaks.com/topic/139150-passing-an-array-to-a-method/#findComment-727778 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... Link to comment https://forums.phpfreaks.com/topic/139150-passing-an-array-to-a-method/#findComment-727779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.