I have about 15 categories with different names and I'm using an if condition to check which value is coming. For example, one section contains cars, motors, parts, etc.; another contains jobs, jobs wanted, job offers, etc.
Here are example possible URLs:
Instead of writing a condition for each possibility:
<?php if($_GET['subcatename'] == 'Cars')
// Show Car Form
//...
<?php if($_GET['subcatename'] == 'Motors')
// Show Motor Form
//...
I want to use code like this:
<?php if($_GET['subcatename'] == 'Cars,Motors') //Will this work ?
{
?>
// Show Motor Form If any of above value in url is appears, cars, motors or etc
<?php
}
?>
Or this:
if($_GET['catename'] = 'cars, motors, parts')
How can I do this?
If you have the following html for your checkboxes:
<input type="checkbox" name="catename[]" value="cars"> cars
<input type="checkbox" name="catename[]" value="motors"> motors
// etc
You can access it as an array (note it will likely be POST, not GET):
var_dump($_POST['catename']);
// array('cars', 'motors')
You can then use in_array
to check for values:
if(in_array('cars', $_POST['catename'])) { ... }