/    Sign up×
Community /Pin to ProfileBookmark

How to set If sentence and specific value inside variable name?

How to set If sentence and specific value inside variable name?

I have defined value for variable which depends on hour.

How to define value to variable name:

[code=php]$myvariablevalue = ; [/code]

and IF sentence defines its value like:

[code=php]
$today == date(“H”);
if ($today == date(“H”)+6 >= 12){

date(“d.m.Y”, strtotime (‘+0 days’));
echo ‘ and  ‘ . date(“d.m.Y”, strtotime (‘+1 days’));

} else {

echo date(“d.m.Y”, strtotime (‘+1 days’));
echo ‘ and ’ . date(“d.m.Y”, strtotime (‘+2 days’));

}
[/code]

Need to store value inside variable from IF sentence like example:
echo date(“d.m.Y”, strtotime (‘+1 days’));
echo ‘ and ’ . date(“d.m.Y”, strtotime (‘+2 days’));

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ssystemsJan 16.2012 — Instead of rendering the computed value assign it to the variable.

[code=php]
$yourvariable = '';

if(condition_is_true)
{
$yourvariable = 'value for this condition';
}
else
{
$yourvariable = 'value on else';
}
[/code]
Copy linkTweet thisAlerts:
@toplisekauthorJan 17.2012 — Thank you.
Copy linkTweet thisAlerts:
@ssystemsJan 17.2012 — Anytime. Please mark as answered
Copy linkTweet thisAlerts:
@CharlesJan 17.2012 — [code=php]$yourvariable = $condition_is_true ? 'value for this condition' : 'value on else';[/code]
Copy linkTweet thisAlerts:
@toplisekauthorJan 18.2012 — If there is value for particular SESSION how to set IF sentence in this case not POST method. Notice... because SESSION will have its value or other SESSION value will be used.

Sample:
[code=php]

$yourvariable = $_POST['var']==... ? 'value for this condition' : ' other session value on else';

[/code]
Copy linkTweet thisAlerts:
@ssystemsJan 20.2012 — Just follow the same format

[code=php]
$variable = condition ? value_on_true : value_on_false;
[/code]


So you will end up with

[code=php]
$variable = $_SESSION[key] == 'value' ? value_on_true : value_on_false;
[/code]


Of course you have to check for existence
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...