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

  • Home
  • SEARCH
  • 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 8236167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:03:49+00:00 2026-06-07T19:03:49+00:00

Ok so I have value being returned from a database in an ARRAY Some

  • 0

Ok so I have value being returned from a database in an ARRAY Some pages have 3 values, and some pages have 10, and other have 0.

If a page returns a value I want the label to appear ONCE, hence not in the loop.
label -> $key_label = '<span class="hl_reference"><u>key references:</u></span>';

If the page doesn’t have any $reference_keys I don’t want the label to appear, hence $key_label = false;

So I want to check the ARRAY for a value and if >= 1: the label will also appear.

My code doesn’t seem to be validating if(array($value => 1) && !$key_label) I guess my syntax is wrong or maybe I should be using a different function?

Thanks for help!

$key_label = false;
$key_label = '<span class="hl_reference"><u>key references:</u></span>';

foreach($reference_keys as $value)
{
    echo $value .'&nbsp;';
}

if(array($value => 1) && !$key_label) 
{
    $key_label = true; 
    echo $key_label;
};

——————————-UPDATE—————————–

This code appears to only work on pages with only 1 reference_key… Strange as count is set to >= 1

$key_label = '<span class="hl_reference"><u>key references:</u></span>';

foreach($reference_keys as $value)
{
   echo $value .'&nbsp;';
}
$result = count($value);
if ($result > 1)
{
  echo $key_label;
}   

——————————-UPDATE—————————–

Most recent code by John C appears to work but it displays a “1” immediately before the 2nd $reference_key on each page. But it does only display on pages with $reference_key

$key_flag = false;
$key_label = '<span class="hl_reference"><u>key references:</u></span>';

foreach($reference_keys as $value)
{
if (!empty($value)) {
    if (!$key_flag) {
        echo $key_label;
        $key_label = true;
    }
    echo $value .'&nbsp;';
}
};

——————————-UPDATE—————————–

John C solved this one.. Working code below! Thank you everyone! ->

$key_flag = false;
$key_label = '<span class="hl_reference"><u>key references:</u></span>';

foreach($reference_keys as $value)
{
if (!empty($value)) {
    if (!$key_flag) {
        echo $key_label;
        **$key_flag = true;**
    }
    echo $value .'&nbsp;';
}
};
  • 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-07T19:03:50+00:00Added an answer on June 7, 2026 at 7:03 pm

    If I read this right, you would like to display the span if there are values in your $reference_keys array, then loop through and show the values in the array.

    To do this, you could do something like:

    if (!empty($reference_keys) && count($reference_keys) > 0) {
        echo '<span class="hl_reference"><u>key references:</u></span>';
        foreach($reference_keys as $value)
        {
           echo $value .'&nbsp;';
        }
    }
    

    EDIT If there are empty values in the $reference_keys array, then the count will come back greater than 0 but no keys will show. If this is the case this code will work around:

    $key_flag = false;
    $key_label = '<span class="hl_reference"><u>key references:</u></span>';
    
    foreach($reference_keys as $value)
    {
        if (!empty($value)) {
            if (!$key_flag) {
                echo $key_label;
                $key_flag = true;
            }
            echo $value .'&nbsp;';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array being returned from the database that looks like so: $data
I have a web application which uses the globalization values being passed from sql
I have an html table containing values that are being generated from javascript. How
I have a select list which is being populated using the values from a
I have a text being returned from SQL that may have newlines in it.
I have a dropdownlist that is being populated from a database. That is working
I have an unordered list that's being generated from a database. Depending on the
I have following code that does not work due to a being a value
Dictionary cannot have two values with same key. please tell which logic/algorithm being used
I have used localStorage[key] and key being different strings to store my values while

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.