PHP variable default value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ubiratan
Forum Newbie
Posts: 2
Joined: Wed Jan 04, 2012 1:48 pm

PHP variable default value

Post by ubiratan »

friends,

I do not know practically nothing of PHP, I would rely on help from friends of the forum.

In the code below would like to bring the variable UF loaded with a default value, EXAMPLE: UF = "PR"

/></td>
<td >UF:<br />
<input name="uf" title="Informe o estado" type="text" class="campoCadastro" id="uf" value="<?=$_POST['uf']?>" maxlength="2" style="width:25px;
<?php
$nomeCampoVerifica = "uf";
if($_POST["ACAO"]=="novoCadastro" && $_POST[$nomeCampoVerifica]==""){?>
border:1px #F00 solid;
<?php }; ?>"
/></td>

Muito obrigado
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP variable default value

Post by social_experiment »

Code: Select all

<?php
 $uf = 'topic';

 // will echo UF: topic
 echo 'UF: ' . $uf;
?>
Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ubiratan
Forum Newbie
Posts: 2
Joined: Wed Jan 04, 2012 1:48 pm

Re: PHP variable default value

Post by ubiratan »

thanks for replying.

only blank, something like this:

<?php
if empty($UF){
$uf = 'topic';
}
// will echo UF: topic
echo 'UF: ' . $uf;
?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP variable default value

Post by social_experiment »

You can also define $UF if you want; uppercase letters are normally used for constants and if you do have $UF and $uf they are 2 different variable as variable names in php are case-sensitive.
http://www.php.net/manual/en/language.v ... basics.php
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply