---
title: "värde på flera checkbox i array"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/77678-värde-på-flera-checkbox-i-array"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "ironhead"
published: "2003-05-21T18:47:54.000Z"
updated: "2003-05-21T20:37:39.000Z"
replies: 4
views: 417
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/77678-värde-på-flera-checkbox-i-array"
---

# värde på flera checkbox i array

## #1 — ironhead, 2003-05-21T18:47Z

Vad gör jag för fel?

Har ett formulär som ser ut såhär:

```
<form action="sida.php" method="post">
<input type="checkbox" name="chk" value="Ishockey">
<input type="checkbox" name="chk" value="Fotboll">
<input type="checkbox" name="chk" value="Bandy">
<input type="checkbox" name="chk" value="Basket">
<input type="submit">
</form>
```

Tar emot med:

```php
$MyArray = explode(",",$_POST["chk"]);
$total = count($MyArray);
```

 

...men om jag kryssar i alla rutor får jag bara värdet 1 på $total istf 3......vad är fel?

Testade detta i ASP, och det funkade bra....men hur i PHP????

```
MyArray = Split(request.form("chk"), ",")
intIndex = ubound(MyArray)
```

Permalänk: https://www.webforum.nu/p/77678

## #2 — Matte, 2003-05-21T19:45Z

```
<form action="sida.php" method="post">
<input type="checkbox" name="chk[]" value="Ishockey">
<input type="checkbox" name="chk[]" value="Fotboll">
<input type="checkbox" name="chk[]" value="Bandy">
<input type="checkbox" name="chk[]" value="Basket">
<input type="submit">
</form>
```

 
Och sen när du tar emot:

```
foreach ($_POST['chk'] as $val) {
   echo $val."<br>";
}
```

Permalänk: https://www.webforum.nu/p/1057882

## #3 — ironhead, 2003-05-21T20:18Z

Nice! Tackar!  :)

Permalänk: https://www.webforum.nu/p/1057921

## #4 — ironhead, 2003-05-21T20:31Z

Kan jag få ut "count" på denna?

Permalänk: https://www.webforum.nu/p/1057933

## #5 — Matte, 2003-05-21T20:37Z

```
$total = count($_POST['chk']);
```

 
Först kanske du bör kolla att variabel $\_POST\['chk'\] överhuvudtaget finns. Kryssas ingen checkbox i så kommer heller inte någon variabel $\_POST\['chk'\] att finnas.

Permalänk: https://www.webforum.nu/p/1057943

---

Tråden på webben: https://www.webforum.nu/amne/php/77678-värde-på-flera-checkbox-i-array
