Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alihoushyaripour's avatar

Why boolean parameters with the 'false' value, not received in request?

Hi,

Assume I received two parameter with bool1 and bool2 that are boolean and bool1 has been initialized with true and bool2 with false

Now this is my log:

Array
(
    [bool1] => 1
    [bool2] => 
)

bool2 not initialized with any value, but why?

0 likes
5 replies
tykus's avatar

Unchecked checkboxes are not sent.

1 like
Sergiu17's avatar
<?php

echo true;
echo false;

When you open this in browser, the output will be

1
1 like
jlrdw's avatar

Which has been discussed many times here and it's basic HTML.

You yourself have to set up the logic to determine if nothing was passed.

Cruorzy's avatar
<input type="hidden" name="something" value="0" />
<input type="checkbox" name="something" value="1" />

when checked it overrides the hidden value.

2 likes
Cronix's avatar

or just

<input type="checkbox" name="something" value="1" />

and

$value = (int)$request->has('something');

$value will be 1 if the checkbox was checked, or 0 if it wasn't.

2 likes

Please or to participate in this conversation.