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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:18:36+00:00 2026-05-15T20:18:36+00:00

I was looking to see if it’s possible to set multiple variables with one

  • 0

I was looking to see if it’s possible to set multiple variables with one ternary operator. I google’d a bit, but didn’t come up with anything. I started testing a few ideas, and found something close — but also getting some strange behavior; any ideas as to what’s going on? And, is it possible to set more than one var in a single ternary operation? If so, is there a proper way of doing it?

$i=9;
($i==9)?($w=3|$r=2):($w=7|$r=1);
echo 'w= '.$w.' r= '.$r;//w= 3 r= 2


$i=9;
($i==9)?($w=4|$r=2):($w=7|$r=1);
echo 'w= '.$w.' r= '.$r;//w= 6 r= 2


$i=9;
($i==9)?($w=3|$r=7):($w=7|$r=1);
echo 'w= '.$w.' r= '.$r;//w= 7 r= 7


$i=444;
($i==9)?($w=4|$r=2):($w=7|$r=1);
echo 'w= '.$w.' r= '.$r;//w= 7 r= 1


$i=444;
($i==9)?($w=4|$r=2):($w=1|$r=1);
echo 'w= '.$w.' r= '.$r;//w= 1 r= 1 

Thanks…


Edit:

I did a little more testing, and found that this works correctly:

    ($i==9)?($w=4 AND $r=7):($w=7 AND $r=1);

however, I’m not sure if this is correct. And I’m curious as to what’s going on in the first example.

  • 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-15T20:18:37+00:00Added an answer on May 15, 2026 at 8:18 pm

    As Chadwick has explained, using the AND or OR logical operators will not work the way you want them to:

    $i = 0; $w = 0; $r = 0;
    ($i==9) ? ($w=4 AND $r=7) : ($w=7 AND $r=1);
    echo "w = $w, r = $r\n";
    // w = 7, r = 1
    
    $i = 0; $w = 0; $r = 0;
    ($i==9) ? ($w=0 AND $r=7) : ($w=0 AND $r=1);
    echo "w = $w, r = $r\n";
    // w = 0, r = 0
    

    However, if you really want to make multiple assignments in one statement, you can use the list construct:

    $i = 0; $w = 0; $r = 0;
    ($i==9) ?
        (list($w, $r) = array(4, 7)) :
        (list($w, $r) = array(7, 1));
    echo "w = $w, r = $r\n";
    // w = 7, r = 1
    
    $i = 0; $w = 0; $r = 0;
    ($i==9) ?
        (list($w, $r) = array(0, 7)) :
        (list($w, $r) = array(0, 1));
    echo "w = $w, r = $r\n";
    // w = 0, r = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried looking to see if this is possible, but I can't find my
I'm looking to see if it's possible to access the value of a key
Many times I see Looking for .NET Developer but doesn't specify whether you'll be
Looking to see if something is technically possible before embarking on its development. The
I'm looking to see if something is possible, or some ideas if it isn't...
Ok I am looking into see if it is possible to get the DNS
I'm looking to see if it's possible to pull data from individual posts; listed
I'm looking to see if it's possible for me to code something maybe in
I am looking to see if it's, first, possible to even use javascript to
I'm looking to see if an array has one or more values inside it.

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.