rbrown Posted May 27, 2008 Share Posted May 27, 2008 I have five arrays and I want to be able to select the array used based on the request_uri by prepending the array it is calling. So if I had /search/cars/index.php or /search/trucks/index.php And I explode it using / then I want to prepend the name of the array I'm calling So it would be $exploded_uri['2']_array would call the $cars_array or $trucks_array depending on the url I'm trying not to use a switch statement. I'm trying to write the code so I can just add a new array to the master array page, create the folder and plop the index.php in and be done without having to mod the page or groups of pages. Can it be done? I have tried a bunch of different ways and I can't get it to work. Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/107401-using-a-var-to-prepend-an-array-name/ Share on other sites More sharing options...
sasa Posted May 27, 2008 Share Posted May 27, 2008 try[code[<?php $a = '/search/cars/index.php'; //$a = '/search/trucks/index.php'; $trucks_array = array('truck1', 'Truck2'); $cars_array = array('car1', 'car2'); $a = explode('/', $a); echo ${$a[2].'_array'}[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107401-using-a-var-to-prepend-an-array-name/#findComment-550767 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.