Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:14:46+00:00 2026-06-06T07:14:46+00:00

I have three variables ($var, $var2 & $var3) and I want it to output

  • 0

I have three variables ($var, $var2 & $var3) and I want it to output when they have value.

For example, if $var = "Data"; then:

<ul>
<li>Data</li>
</ul>

And if any of the other variables has value then:

<ul>
<li>Data</li>
<li>Data2</li>
</ul>

Or

<ul>
<li>Data</li>
<li>Data3</li>
</ul>

<ul>
<li>Data</li>
<li>Data3</li>
<li>Data2</li>
</ul>

I am not exactly sure how to create this and with what method considering everybody has different ways of doing their php code. Does anybody know how I can create this?

Also: I use http://writecodeonline.com/php/ when testing certain php codes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:14:48+00:00Added an answer on June 6, 2026 at 7:14 am
    <ul>
        <?php foreach (array($var1, $var2, $var3) as $var) : ?>
            <?php if (!empty($var)) : ?>
                <li><?php echo $var; ?></li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>
    

    You can see the output here on writecodeonline.com.


    Or maybe you prefer this:

    <ul>
        <?php
        foreach (array($var1, $var2, $var3) as $var) {
            if (!empty($var)) {
                echo '<li>' . $var . '</li>';
            }
        }
        ?>
    </ul>
    

    (it doesn’t matter really, just use whatever you think looks better)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three variables that may or may not contain data. let's call them
Suppose I have, class example(object) def __init__(var1 = 10, var2 = 15, var3 =
I have a bunch of variables that I want to check, and if they
Another newbie question that has me stuck badly. I have three variables var state1
I have defined three variables a,b,c before a while loop, then compute a new
I'm constructing a class where I have three member variables that I want to
I have three boolean variables. I need to check if all three are true
I have declared three variables namely TemplateData tData; TaskInstance tInstance;int tID; in my program.
I have three separate table variables in my Function, 1 of them is not
I have used following code to add three variables but instead of adding these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.