String Sum: Array - Sum Explode Echo
String Sum: Array - Sum Explode Echo
String Sum: Array - Sum Explode Echo
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'] = '';
}
}
?>
print ">";
if ($_SESSION['value2'] == 2)
{
print ' checked="checked"';
}
print ">";
print ">";
print 'Induksi Riset';
print '<br>';
print ">";
print 'Skripsi';
print '<br>';
?>
<br>
<input type="submit" name="submit" value="Save" />
</form>