See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

PHP one line, different variables [closed]

General Tech Bugs & Fixes
Max. 2000 characters

Alice Davidson


( 7 months ago )

I have a php file with multiple lines that are identical in all ways, except for the variable displayed in them. At the moment, there are 26 lines of code, but can be reduced to two if there's a way to repeat the static php and place the dynamic variables in their required place. I'm asking for a place I can find some documentation on the function I'm looking for, or for an example that can help me work this out.

Some sample code:

<div id="DynamicName" <?php if ( $Survival == "Online" )
{echo "class='span2 up'><div class=service><div class=name>Survival</div><h2 class=status></h2>";}
else {echo "class='span2 down'><div class=service><div class=name>Survival</div><h2 class=status></h2>";} ?></div>

<div id="DynamicName2" <?php if ( $DynamicName2 == "Online" )
{echo "class='span2 up'><div class=service><div class=name>DynamicName2</div><h2 class=status></h2>";}
else {echo "class='span2 down'><div class=service><div class=name>DynamicName2</div><h2 class=status></h2>";} ?></div>

This is not the full code, but is the required portion that needs to be repeated.

what's your interest