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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:41:52+00:00 2026-06-18T09:41:52+00:00

Ive got an if statment which im using in php as part of a

  • 0

Ive got an if statment which im using in php as part of a foreach loop.

What id like to do is make the if statement a variable so that i could just call the variable. Somthing like this

$best_xml = if ($wh_odds_attrib['oddsDecimal'] < $lad_odds_attrib['oddsDecimal']) {
    $lad_odds_attrib['oddsDecimal'];
  }

  else {
    $wh_odds_attrib['oddsDecimal'];
  };

But i keep getting this error when i run it – Parse error: syntax error, unexpected ‘if’ (T_IF) in /Applications/MAMP/htdocs/event.php on line 74 (line 74 is the first line starting $best_xml)

Is this possible / is this the right way to do it ?

  • 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-18T09:41:53+00:00Added an answer on June 18, 2026 at 9:41 am

    if statements don’t evaluate to an assignable value in PHP. You can’t assign an if statement to a variable.

    You can, however, use the ternary operator:

    $best_xml = $wh_odds_attrib['oddsDecimal'] < $lad_odds_attrib['oddsDecimal'] ? 
      $lad_odds_attrib['oddsDecimal'] : $wh_odds_attrib['oddsDecimal'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a choose statement that should be setting my variable but for some
Ive got a div that i want to slide out on click using .show(slide,
I've got a delegate statement that works like so: $(body).delegate(tr[type='option'],'mouseenter',function(){ The problem is that
I've got a managed c++ library that is crashing when a delete statement is
Ive got a div thats hidden with .hide and on click opens using .show(slide,
ive got this exception. My Object looks like this: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ObjectDTO
Ive got the following code which I hacked together from website examples. It works
I've got class which is using plain-only-data struct with const variables and I'm not
I've got the following SQL statement that does a subquery concatenation. If you notice,
I've got a very large application built using Visual Studio 2008 which is designed

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.