Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kazemimorteza68/3d9758b07b7be295446fb17d01643c7b to your computer and use it in GitHub Desktop.
Save kazemimorteza68/3d9758b07b7be295446fb17d01643c7b to your computer and use it in GitHub Desktop.
Extract Values from Multi Select DropDown with PHP
<?php
/**
* File Name: extract-data-from-multi-select.php
* Description: A Simple way to Extract Data from a Multi Select Input and Store in a variable with spearating each values with comma.
* Author: Abdul Awal Uzzal
* Author Url: abdulawal.com
* Article: http://themencode.com/?p=435
*/
if(isset($_POST['select_name'])){ // select_name will be replaced with your input filed name
$getInput = $_POST['select_name']; // select_name will be replaced with your input filed name
$selectedOption = "";
foreach ($getInput as $option => $value) {
$selectedOption .= $value.','; // I am separating Values with a comma (,) so that I can extract data using explode()
}
echo $selectedOption;
}
?>
<form action="" method="POST">
<select name="select_name[]" id="" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<input type="submit">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment