Reputation: 39
I have make function but it doesn't want to work , I don't know why or what the wrong because I think all is good
function ifemptySet($who,$set){
if(empty($who)){
$who = "$set";
}
}
if(isset($_POST['saveinfosite'])){
$site_name = strip_tags($_POST['site_name']);
ifemptySet($site_name,"null");
echo $site_name;
}
When I set the " input " empty , php (echo) doesn't print anything , but when I write something in the "input" , I show only what I have put in the Input
(Sorry for my english)
Upvotes: 0
Views: 108
Reputation: 59681
You just have to change your function header to this:
function ifemptySet(&$who,$set){
//^See here! Passed by reference
if(empty($who)){
$who = "$set";
}
}
Also you could do it with return like this:
function ifemptySet($who,$set){
if(empty($who)){
return $who = "$set";
}
return $who;
}
For more information see: http://php.net/manual/en/language.references.pass.php
Upvotes: 1
Reputation: 12039
Return the value from ifemptySet()
& assign it to $site_name
. Can try this
function ifemptySet($who,$set){
return $who ? $who : $set;
}
if(isset($_POST['saveinfosite'])){
$site_name = strip_tags($_POST['site_name']);
$site_name = ifemptySet($site_name, "null");
echo $site_name;
}
Upvotes: 0