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 4111954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:07:56+00:00 2026-05-20T22:07:56+00:00

I have an array that goes like this $array = array(‘key1’ => $_GET[‘value1’], ‘key2’

  • 0

I have an array that goes like this

$array = array('key1' => $_GET['value1'], 'key2' => $_GET['value2']);

I want to check if the key’s value is not empty. Say a user goes to the webpage and requests this
http://mysite.com/page.php?value1=somevalue&value2= which means that value2 is empty or say that it is missing from the query string i want to be able to check if it’s there and is not empty.

I tried this

foreach($array as $key => $value)
{
    if(empty($value))
    {
        //spout some error
    }
}

but even though i enter this http://mysite.com/page.php?value1=somevalue meaning that value2 is missing, i don’t get the error.

How do i achieve what i want?

  • 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-05-20T22:07:57+00:00Added an answer on May 20, 2026 at 10:07 pm

    When I do this:

    <?php 
    
    $array = array('key1' => $_GET['value1'], 'key2' => $_GET['value2']);
    
    foreach($array as $key => $value)
    {
        if(empty($value))
        {
            echo "$key empty<br/>";
        }
        else
        {
            echo "$key not empty<br/>";
        }
    }
    
    ?>
    

    With:

    http://jfcoder.com/test/arrayempty.php?value1=somevalue

    EDIT: And this – http://jfcoder.com/test/arrayempty.php?value1=somevalue&value2=

    I get:

    key1 not empty
    key2 empty
    

    I’m thinking you need to give more context to your question about actual use, since there is probably some other detail throwing it off.

    EDIT

    This doesn’t make any sense, but this was provided in a comment:

    $array = array(
        'key1' => '".mysql_real_escape_string($_GET['value1'])."',
        'key2' => '".mysql_real_escape_string($_GET['value2'])."'
    );
    

    This actually doesn’t parse due to the single quotes being mixed in with the single quoted string, and the fact that this, even if it did parse, would set the array piece equal to the literal string, not the function result.

    I gather that maybe it was:

    $array = array(
        'key1' => "'".mysql_real_escape_string($_GET['value1'])."'",
        'key2' => "'".mysql_real_escape_string($_GET['value2'])."'"
    );
    

    Which would indicate that a string would always be returned that was at least '', which would never be empty, due to the single quotes.

    Consider PDO.

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

Sidebar

Related Questions

I have a dataset obtained from MySQL that goes like this: Array ( [0]
I have byte array as input. I would like to convert that array to
I have a PHP script that goes through an XML file, but I want
I have an array of strings that I want to try and match to
I have an array that contains a list of vertices which I copy to
Say I have an array that represents a set of points: x = [2,
I have a byte array that represents a complete TCP/IP packet. For clarification, the
I have an array of filenames and need to sort that array by the
I have an array of numbers that potentially have up to 8 decimal places
I have a large 2d array that I serialize and base64_encode and throw into

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.