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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:41:13+00:00 2026-06-11T12:41:13+00:00

<?php $s1=;$s2=qwe;$s3=zxc; if(!empty($s1)) { $result=$s1; } else { if(!empty($s2)) { $result=$s2; } else {

  • 0
<?php
$s1="";$s2="qwe";$s3="zxc";

if(!empty($s1))
{
    $result=$s1;
}
else
{
    if(!empty($s2))
    {
        $result=$s2;
    }
    else
    {
        $result=$s3;
    }
}

echo "$result";
?>

Is there any possible code, probably of 1-2 lines, replacing the above mentioned code, I remember something like using “or” operator to do what I am doing with this code.

  • 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-11T12:41:14+00:00Added an answer on June 11, 2026 at 12:41 pm
    $result = $s1 ? $s1 : ($s2 ? $s2 : $s3);
    

    Or even shorter, if you have PHP >5.3:

    $result = $s1 ?: ($s2 ?: $s3);
    

    More: PHP Manual part about Ternary Operator

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

Sidebar

Related Questions

PHP code: echo date(c); //out put like this 2012-06-19T20:37:44+05:30 echo date(d M, Y); //out
PHP code: echo hash('sha256', 'jake'); PHP output: cdf30c6b345276278bedc7bcedd9d5582f5b8e0c1dd858f46ef4ea231f92731d Java code: String s = jake;
PHP treats all arrays as associative, so there aren't any built in functions. Can
PHP CODE $t = strtotime( '2012-09-21T03:00:00+00:00 America/Chicago' ); $t2 = date('c',$t); echo $t2; OUPUT
PHP Array logic re-factor I'm trying to re-factor my code... This is PHP ...
PHP returns largest possible random value 32767 on windows? What is constraint on windows?
PHP DOM automatically decodes. Eg &#42; is decoded when creating a DOMElement. Is there
PHP script $count = 0; foreach ($_FILES['filesToUpload'] as $file) { //upload process echo $file[$count]['tmp_name'].',';
PHP code: $key = 12345678abcdefgh12345678abcdefgh; $iv = 12345678abcdefgh; $plaindata = This is a test
PHP: Any ideas where I could find a script similar to what stackoverflow uses?

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.