String Sum: Array - Sum Explode Echo

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1.

String sum
<?php
$v = "1-2-3-4-5-6-7-8";
$sum = array_sum( explode( '-', $v ) );
echo $sum;
?>

2. Form textfield

<!DOCTYPE html>
<html>

<body>
<form method = 'post' action= "">
<table>
<tr>
<td>Umur</td>
<td>:</td>
<td><input type='text' name='umur'></td>
</tr>

</table>
<input type='submit' value='KIRIM' name="submit">
</form>
</body>
</html>

<?php
if (isset($_POST['submit'])) {
$umur = $_POST['umur'];
if(!is_numeric ($umur))
echo "error";
else{
if($umur >= 17){
echo "selamat Datang";
}
else {
echo "maaf";
}
}

}
?>

3. Form Checkbox
<?php
session_start();
if(isset($_POST['submit']))
{
if(isset($_POST['web']))
{
$_SESSION['value'] = $_POST['web'];
}
else
{
$_SESSION['value'] = '';
}
if(isset($_POST['datmin']))
{
$_SESSION['value2'] = $_POST['datmin'];
}
else
{
$_SESSION['value2'] = '';
}
if(isset($_POST['inset']))
{
$_SESSION['value3'] = $_POST['inset'];
}
else
{
$_SESSION['value3'] = '';
}
if(isset($_POST['skripsi']))
{
$_SESSION['value4'] = $_POST['skripsi'];
}
else
{
$_SESSION['value4'] = '';
}
}
?>

<form action="" method="POST">


<?php
print '<input name="web" type="checkbox" value="1" id="web" ';
if ($_SESSION['value'] == 1)
{
print ' checked="checked"';
}

print ">";

print 'Pemrograman Web';


print '<br>';

print '<input name="datmin" type="checkbox" value="2" id="datmin" ';

if ($_SESSION['value2'] == 2)
{
print ' checked="checked"';
}

print ">";

print 'Data Mining';


print '<br>';
print '<input name="inset" type="checkbox" value="3" id="inset" ';
if ($_SESSION['value3'] == 3)
{
print ' checked="checked"';
}

print ">";
print 'Induksi Riset';
print '<br>';

print '<input name="skripsi" type="checkbox" value="4" id="skripsi" ';


if ($_SESSION['value4'] == 4)
{
print ' checked="checked"';
}

print ">";
print 'Skripsi';
print '<br>';

?>
<br>
<input type="submit" name="submit" value="Save" />
</form>

You might also like