Reputation: 35
I have a php function which gets a value from previous page but I want to have an existing value just in case if I leave the field empty.
Example:
$age = $_POST['age'];
want to add if statament if age is empty user 50 as a value
Upvotes: 1
Views: 58
Reputation: 46620
<?php
//Standard If Else
if(isset($_GET['age']) && is_numeric($_GET['age'])){
$age = $_GET['age'];
}else{
$age = 50;
}
// Or a One-line Ternary
$age = isset($_GET['age']) && is_numeric($_GET['age']) ? $_GET['age'] : 50;
?>
Upvotes: 0