Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to $_GET multiple checkbox values? [duplicate]

<input type="checkbox" name="currency" value="usd"/>
<input type="checkbox" name="currency" value="euro"/>
<input type="checkbox" name="currency" value="cad"/>

Im trying to get currency values through $_GET request, something like /?currency=usd,cad but instead im getting /?currency=usd&currency=cad and then $_GET['currency'] returns only one value.

adding name=currency[] just gets /?currency[]=usd&currency[]=cad

What is the proper way to get these checkbox values in some sort of array?

like image 628
skyisred Avatar asked Dec 22 '25 17:12

skyisred


1 Answers

HTML:

<input type="checkbox" name="currency[]" value="usd"/>
<input type="checkbox" name="currency[]" value="euro"/>
<input type="checkbox" name="currency[]" value="cad"/>

PHP:

<?php
foreach($_GET['currency'] as $currency){
  echo $currency."<br/>";
  //or what ever
}
?>
like image 67
This_is_me Avatar answered Dec 24 '25 07:12

This_is_me



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!