3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $certidoes = array( array( 'id_certidao' => 1, 'checked' => 1 ), array( 'id_certidao' => 2, 'checked' => 0 ), array( 'id_certidao' => 3, 'checked' => 1 ) ); foreach ($certidoes as $certidao) { $checked = ""; if ($certidao['checked']) { $checked = "checked"; } echo '<input type="checkbox" id="check_'.$certidao['id_certidao'].'" name="check['.$certidao['id_certidao'].']" ' . $checked . ' value="1" /><br /><br />'; } //Dados para teste $_POST['check'] = array( 0 => 1, 1 => 3 ); $_POST['emissao'] = array( 1 => '10/10/2013', 2 => '11/10/2013', 3 => '12/10/2013' ); $_POST['validade'] = array( 1 => '10/10/2013', 2 => '10/11/2013', 3 => '10/12/2013' ); if (isset($_POST['check'])) { foreach ($_POST['check'] as $id) { $id_certidao = filter_var($id, FILTER_SANITIZE_NUMBER_INT); $emissao = filter_var($_POST['emissao'][$id_certidao], FILTER_SANITIZE_STRING); $validade = filter_var($_POST['validade'][$id_certidao], FILTER_SANITIZE_STRING); $insert = "INSERT INTO tb_certidao VALUES ( '$id_certidao', '$emissao', '$validade' )"; echo $insert.'<br><br>'; } }
Output for 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<input type="checkbox" id="check_1" name="check[1]" checked value="1" /><br /><br /><input type="checkbox" id="check_2" name="check[2]" value="1" /><br /><br /><input type="checkbox" id="check_3" name="check[3]" checked value="1" /><br /><br />INSERT INTO tb_certidao VALUES ( '1', '10/10/2013', '10/10/2013' )<br><br>INSERT INTO tb_certidao VALUES ( '3', '12/10/2013', '10/12/2013' )<br><br>
Output for 5.0.0 - 5.1.6
<input type="checkbox" id="check_1" name="check[1]" checked value="1" /><br /><br /><input type="checkbox" id="check_2" name="check[2]" value="1" /><br /><br /><input type="checkbox" id="check_3" name="check[3]" checked value="1" /><br /><br /> Fatal error: Call to undefined function filter_var() in /in/33uT0 on line 46
Process exited with code 255.
Output for 4.4.5 - 4.4.9
<input type="checkbox" id="check_1" name="check[1]" checked value="1" /><br /><br /><input type="checkbox" id="check_2" name="check[2]" value="1" /><br /><br /><input type="checkbox" id="check_3" name="check[3]" checked value="1" /><br /><br /> Fatal error: Call to undefined function: filter_var() in /in/33uT0 on line 46
Process exited with code 255.
Output for 4.3.2 - 4.4.4
<input type="checkbox" id="check_1" name="check[1]" checked value="1" /><br /><br /><input type="checkbox" id="check_2" name="check[2]" value="1" /><br /><br /><input type="checkbox" id="check_3" name="check[3]" checked value="1" /><br /><br /> Fatal error: Call to undefined function: filter_var() in /in/33uT0 on line 46
Process exited with code 255.
Output for 4.3.0 - 4.3.1
<input type="checkbox" id="check_1" name="check[1]" checked value="1" /><br /><br /><input type="checkbox" id="check_2" name="check[2]" value="1" /><br /><br /><input type="checkbox" id="check_3" name="check[3]" checked value="1" /><br /><br /> Fatal error: Call to undefined function: filter_var() in /in/33uT0 on line 46