Total NEWB - php function if variable is null
sorry for asking this dumb question i will try to explain as good as i can, i have never done a php function before, i could solve this with IF but i want to do my first function
What i want to do is to see if the variable is null and if it is i want to set t开发者_如何学Gohe variable to be "N/A"
$carplate=mysql_result($result,0,"plate");
$carbrand=mysql_result($result,0,"brand");
function set_null(variablegoeshere?){
if($WHATiWANTtonull==null){
$WHATiWANTtonull="N/A";
}else{ do nothing }
}
set_null($carplate);
set_null($carbrand);
echo "carplate = $carplate | carbrand = $carbrand";
i dont understand how i will get the function to set a variable to "N/A" or do nothing, i don't want it to echo something, just set a variable and i can echo it later whenever i want
[EDIT]: Use this function:
function set_null(&$var)
{
if($var==null)
{
$var="N/A";
}
}
精彩评论