Help With Dynamic Inclusion from Array


I’m new to PHP and I’m having trouble using an array within my script to replace the string from a variable obtained via the URL with the actual name of a directory. The code is as follows:

<?php $url = ''; if (!empty($_GET['category'])) { $url .= $_GET['category'] . '/'; } if (!empty($_GET['product'])) { $prod = array('stationery pads'=>'01 stationery pads', 'greeting cards'=>'02 greeting cards', 'magnetic pads'=>'03 magnetic pads', 'journals with locks'=>'04 journals with locks', 'spiral notebooks'=>'05 spiral journals', 'sets'=>'90 sets', 'featured'=>'99 new - featured'); $url .= $prod[$_GET['product']] . '/'; } if (!empty($_GET['page'])) { $url .= $_GET['page'] . '.php'; } echo $url; ?>

Again, I’m new to PHP and I’m sure it’s a simple remedy to fix my coding. Any help you can provide would be greatly appreciated. Thanks! :slight_smile:

  • Mike
Sponsor our Newsletter | Privacy Policy | Terms of Service