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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:56:54+00:00 2026-06-13T14:56:54+00:00

I have a PHP script that runs through an array of values through my

  • 0

I have a PHP script that runs through an array of values through my own custom function that uses the PHP function preg_match. It’s looking for a match with my regular expression being $valueA, and my string to search being $valueB, and if it finds a match, it returns it to $match, otherwise I don’t want my IF statement to run.

Now, I’m having no problem with this IF statement running if the function finds a match (in other words, is TRUE);

if ($match = match_this($valueA, $valueB))
{
    //do this
}

HOWEVER, if I wanted to compare an additional condition to check if it is also TRUE, and only run the IF statement when both are TRUE, I run into problems;

if ($match = match_this($valueA, $valueB) && $x == 'x')
{
    //do this
}

Instead of the statement running as normal when both conditions are TRUE, I end up outputting a 1 from $match instead of what my $match value should be.

I can sort of see what’s happening. My IF statement is just returning a literal boolean TRUE into $match, instead of my value returned from match_this();

Is this because I can only return one sense of TRUE?

I can get around the problem by having two nested IF statements, but for the sake of clean code I’d like to be able to compare multiple conditions in my IFs which includes functions that return values.

Are there different kinds of TRUE? If so, how do I compare them in this way? Or is there an easier method? I suppose I could just put a second IF statement inside my function and pass my second condition through the function, but then my function wouldn’t be very clearly defined in terms of its purpose.

I’ve ran into this problem before and didn’t quite know what I was looking for. Hope someone can help.

  • 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-13T14:56:55+00:00Added an answer on June 13, 2026 at 2:56 pm
    if (($match = match_this($valueA, $valueB)) && $x == 'x') 
        ^                                     ^
    

    You missed an extra set of brackets.
    Without the extra set of brackets around $match = match_this($valueA, $valueB), the evaluation of the && is performed first and finally result is assigned to $match.

    Alternatively, you could use and (which has lower precedence than assignment =) instead of &&

    PHP Operator Precedence

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

Sidebar

Related Questions

I have a script that runs through a multi-level array and each time calls
I have a php script that runs a mysql query, then loops the result,
I have a command-line PHP script that runs a wget request using each member
I have a php script that is run once a minute. The script runs
I have a PHP script that runs on cron that can take up to
I have a php script that runs some checks, if the checks fail it
I have a PHP script that runs once a day, and it takes a
I have developed a script that uses php's imap_search and when it gets to
I have a PHP script that runs database queries. Now, if a query fails,
I have a PHP script that imports CSV files and goes through tens of

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.