/    Sign up×
Community /Pin to ProfileBookmark

What Is This Php Line ? Short Code Condition ? How So ?

Folks,

What this means ? Let me know so I get sure it is what I think it is.

““
$page = ISSET($_GET[‘page’]) && is_numeric($_GET[‘page’]) ? $_GET[‘page’] : 1;
““

How come there is no “IF” or “ELSE” ?
Which part acts as “IF” and which part acts as “ELSE” ?
What does the “:” mean ?

I would do it like this ….

““
if(ISSET($_GET[‘page’]) && is_numeric($_GET[‘page’])
{
$page = $_GET[‘page’];
}
else
{
$page = 1;
}

““

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@cootheadAug 22.2020 — Hi there developer_web,

It is a....
  • 1. [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator][color=#00f][u]JavaScript Conditional - ( ternary ) - operator[/u][/color][/url]


  • 2. [url=https://www.geeksforgeeks.org/php-ternary-operator/][color=#00f][u]PHP | Ternary Operator[/u][/color][/url]


  • [i]coothead[/i]
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 23.2020 — @coothead#1622396

    Oh Thanks. I thought it was just php.
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 23.2020 — 
    ISSET($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;



    ISSET($_GET['page'] && is_numeric($_GET['page'])) ? $_GET['page'] : 1;


    Which one would you refuse and why out of the two ?
    Copy linkTweet thisAlerts:
    @NogDogAug 23.2020 — > @developer_web#1622410 Which one would you refuse and why out of the two ?

    I'd use #1 since #2 would throw an error. While not strictly necessary, I'd probably add parens to make it clear what the boundaries are of the initial conditional expression:
    <i>
    </i>$something = ( ISSET($_GET['page']) &amp;&amp; is_numeric($_GET['page']) ) ? $_GET['page'] : 1;

    Bonus tip, don't start using ternary operators everywhere you possibly can: they can reduce code readability, and the only performance boost you're getting is that maybe you don't have to type quite as many characters (which can be a false savings in the long run).
    Copy linkTweet thisAlerts:
    @VITSUSAAug 24.2020 — @coothead#1622396 This is a perfect solution, and a good platform for learning also.
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 24.2020 — @NogDog#1622414

    Did you miss any closing racket at the end ?


    $something = ( ISSET($_GET['page']) && is_numeric($_GET['page']) ) ? $_GET['page'] : 1;
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 24.2020 — @VITSUSA#1622419

    What do you mean ? Which platform ?

    Anyway, I'd like you to engage in my threads often if not stayed glued to them or if not keep your radar on for my new threads.

    :)
    Copy linkTweet thisAlerts:
    @NogDogAug 24.2020 — > @developer_web#1622436 Did you miss any closing racket at the end ?

    Nope.
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 24.2020 — ISSUE: SOLVED.

    Thread can close.
    Copy linkTweet thisAlerts:
    @hemangjoshi37aAug 31.2020 — @developer_web#1622477 Yes bro..


    Hemang Joshi,

    Web Designer,

    **Links removed by Site Administrator so it doesn't look like you're spamming us. Please don't post them again.**
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 07.2021 — Nearly a year later, asking again for thread to be closed.

    But answer one thing NogDog, before you do close it.

    Which one better in which circumstance:
    <i>
    </i>$page = ISSET($_GET['page']) &amp;&amp; is_numeric($_GET['page']) ? (INT)$_GET['page'] : 1;

    I think I got above from NachFolger at one of my threads.

    <i>
    </i>$page = ( ISSET($_GET['page']) &amp;&amp; is_numeric($_GET['page']) ) ? $_GET['page'] : 1;

    Got this from you in this thread.
    Copy linkTweet thisAlerts:
    @Steve_R_JonesmoderatorAug 07.2021 — DO NOT ASK ANY MORE QUESTIONS TODAY!
    Copy linkTweet thisAlerts:
    @Steve_R_JonesmoderatorAug 07.2021 — I banned his account for a period of time. Maybe that will get his attention and he'll reply to the email I sent.
    Copy linkTweet thisAlerts:
    @developer_webauthorAug 18.2021 — @Steve_R_Jones#1635292

    I did not get any email from you. Plus, how come I never heard of you before till nowadays ? How come ? The only Mods I know are NogDog, Sempervivum and maybe one other. Which forum you usually prowl on ? Do you know php ? If so, then I'd be glad if you can answer my threads now and then so NogDog can take a break from answering them.

    PS - I can't believe it's been 11 days. Time passes quickly in Covid period. Just curious how long did you ban me for ?

    Cheers!
    Copy linkTweet thisAlerts:
    @Steve_R_JonesmoderatorAug 18.2021 — @developer_web#1635650 - I edited your user account here and grabbed that email address.... If it isn't a good one you need to fix it. I use a @Gmail account so there is no reason why you didn't get my emails.

    I typed you two notes in this thread.....

    I'm the ADMIN of the site and deal with running it versus writing code.

    YOU ARE over doing it.... here in the very near future we'll limit you to one question a week.
    ×

    Success!

    Help @developer_web spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...