Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMayur Pande
Courses Plus Student 11,711 PointsHow would I add keys to an array, that has been exploded
How would I go about adding keys each element in an array that as been parsed through a .htaccess
file.
so for example the .htaccess
looks like this;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?PATH_INFO=$1 [L,QSA]
so when I run
$request = explode('/',$_GET['PATH_INFO']);
If I passed in the url www.somewebsite.com/movies/title
I would get the result
array(2) { [0]=> string(6) "movies" [1]=> string(5) "title" }
Instead of getting the keys as [0]
and [1]
is there a way I can explicitly give it keys, as for example the domain could change and have more parameters on the end.
Mayur Pande
Courses Plus Student 11,711 PointsI guess as movies would be the controller and title would be the method I want to give it those keys, but I guess I can just use 0, and 1. Just thought for better coding practice it would be better with naming conventions I thought
Alan Fox
10,214 PointsAlan Fox
10,214 PointsWhat keys would you want to give it?
I'm not sure what the point of keys would be instead of 0, 1 etc