Problems with if equals 0












0















'If greater than 1' works...



if (count($resort_results) > 0 && $resort_results['total'] > 0) :


'If equals to 0' doesn't work...



if (count($resort_results) == 0 && $resort_results['total'] == 0) :


When output of $resort_results is:-



array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


I'm probably missing the obvious but why can't I say if $resort_results is zero?










share|improve this question


















  • 1





    Because count of $resort_results isn't 0

    – Mohammad
    Nov 16 '18 at 16:12
















0















'If greater than 1' works...



if (count($resort_results) > 0 && $resort_results['total'] > 0) :


'If equals to 0' doesn't work...



if (count($resort_results) == 0 && $resort_results['total'] == 0) :


When output of $resort_results is:-



array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


I'm probably missing the obvious but why can't I say if $resort_results is zero?










share|improve this question


















  • 1





    Because count of $resort_results isn't 0

    – Mohammad
    Nov 16 '18 at 16:12














0












0








0


0






'If greater than 1' works...



if (count($resort_results) > 0 && $resort_results['total'] > 0) :


'If equals to 0' doesn't work...



if (count($resort_results) == 0 && $resort_results['total'] == 0) :


When output of $resort_results is:-



array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


I'm probably missing the obvious but why can't I say if $resort_results is zero?










share|improve this question














'If greater than 1' works...



if (count($resort_results) > 0 && $resort_results['total'] > 0) :


'If equals to 0' doesn't work...



if (count($resort_results) == 0 && $resort_results['total'] == 0) :


When output of $resort_results is:-



array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


I'm probably missing the obvious but why can't I say if $resort_results is zero?







php






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 16:09









zigojackozigojacko

1,03973061




1,03973061








  • 1





    Because count of $resort_results isn't 0

    – Mohammad
    Nov 16 '18 at 16:12














  • 1





    Because count of $resort_results isn't 0

    – Mohammad
    Nov 16 '18 at 16:12








1




1





Because count of $resort_results isn't 0

– Mohammad
Nov 16 '18 at 16:12





Because count of $resort_results isn't 0

– Mohammad
Nov 16 '18 at 16:12












3 Answers
3






active

oldest

votes


















2














This expression can never be true:



count($resort_results) == 0 && $resort_results['total'] == 0


If the $resort_results['total'] key exists, then count($resort_results) must be at least 1 by definition.



If that array is like this, its count is 2.



array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }
// ^ That's what this 2 means


Maybe you meant



if (count($resort_results['results']) == 0 && $resort_results['total'] == 0)


Just from context I would assume total is a single value and results contains 0 or more results.






share|improve this answer


























  • Yes, that is exactly what I was meant to do - I see now, cheers.

    – zigojacko
    Nov 16 '18 at 16:25



















1














If you have your data...



array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


Then the size of the array is hinted at the start - 2. So when you check



if (count($resort_results) == 0 && $resort_results['total'] == 0) :


The first part is saying if it contains no values, so why bother checking the value if it has no values!



A more common way is to check if the field is not empty and then check the values...



if ( !empty($resort_results['total']) && $resort_results['total'] == 0) :





share|improve this answer































    0














    put three equal when int result



    if (count($resort_results) === 0 && $resort_results['total'] === 0) :






    share|improve this answer
























    • === also check type of values that 0 isn't equal with '0'

      – Mohammad
      Nov 16 '18 at 16:13













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341569%2fproblems-with-if-equals-0%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    This expression can never be true:



    count($resort_results) == 0 && $resort_results['total'] == 0


    If the $resort_results['total'] key exists, then count($resort_results) must be at least 1 by definition.



    If that array is like this, its count is 2.



    array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }
    // ^ That's what this 2 means


    Maybe you meant



    if (count($resort_results['results']) == 0 && $resort_results['total'] == 0)


    Just from context I would assume total is a single value and results contains 0 or more results.






    share|improve this answer


























    • Yes, that is exactly what I was meant to do - I see now, cheers.

      – zigojacko
      Nov 16 '18 at 16:25
















    2














    This expression can never be true:



    count($resort_results) == 0 && $resort_results['total'] == 0


    If the $resort_results['total'] key exists, then count($resort_results) must be at least 1 by definition.



    If that array is like this, its count is 2.



    array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }
    // ^ That's what this 2 means


    Maybe you meant



    if (count($resort_results['results']) == 0 && $resort_results['total'] == 0)


    Just from context I would assume total is a single value and results contains 0 or more results.






    share|improve this answer


























    • Yes, that is exactly what I was meant to do - I see now, cheers.

      – zigojacko
      Nov 16 '18 at 16:25














    2












    2








    2







    This expression can never be true:



    count($resort_results) == 0 && $resort_results['total'] == 0


    If the $resort_results['total'] key exists, then count($resort_results) must be at least 1 by definition.



    If that array is like this, its count is 2.



    array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }
    // ^ That's what this 2 means


    Maybe you meant



    if (count($resort_results['results']) == 0 && $resort_results['total'] == 0)


    Just from context I would assume total is a single value and results contains 0 or more results.






    share|improve this answer















    This expression can never be true:



    count($resort_results) == 0 && $resort_results['total'] == 0


    If the $resort_results['total'] key exists, then count($resort_results) must be at least 1 by definition.



    If that array is like this, its count is 2.



    array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }
    // ^ That's what this 2 means


    Maybe you meant



    if (count($resort_results['results']) == 0 && $resort_results['total'] == 0)


    Just from context I would assume total is a single value and results contains 0 or more results.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 16 '18 at 16:22

























    answered Nov 16 '18 at 16:16









    Don't PanicDon't Panic

    28.7k93756




    28.7k93756













    • Yes, that is exactly what I was meant to do - I see now, cheers.

      – zigojacko
      Nov 16 '18 at 16:25



















    • Yes, that is exactly what I was meant to do - I see now, cheers.

      – zigojacko
      Nov 16 '18 at 16:25

















    Yes, that is exactly what I was meant to do - I see now, cheers.

    – zigojacko
    Nov 16 '18 at 16:25





    Yes, that is exactly what I was meant to do - I see now, cheers.

    – zigojacko
    Nov 16 '18 at 16:25













    1














    If you have your data...



    array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


    Then the size of the array is hinted at the start - 2. So when you check



    if (count($resort_results) == 0 && $resort_results['total'] == 0) :


    The first part is saying if it contains no values, so why bother checking the value if it has no values!



    A more common way is to check if the field is not empty and then check the values...



    if ( !empty($resort_results['total']) && $resort_results['total'] == 0) :





    share|improve this answer




























      1














      If you have your data...



      array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


      Then the size of the array is hinted at the start - 2. So when you check



      if (count($resort_results) == 0 && $resort_results['total'] == 0) :


      The first part is saying if it contains no values, so why bother checking the value if it has no values!



      A more common way is to check if the field is not empty and then check the values...



      if ( !empty($resort_results['total']) && $resort_results['total'] == 0) :





      share|improve this answer


























        1












        1








        1







        If you have your data...



        array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


        Then the size of the array is hinted at the start - 2. So when you check



        if (count($resort_results) == 0 && $resort_results['total'] == 0) :


        The first part is saying if it contains no values, so why bother checking the value if it has no values!



        A more common way is to check if the field is not empty and then check the values...



        if ( !empty($resort_results['total']) && $resort_results['total'] == 0) :





        share|improve this answer













        If you have your data...



        array(2) { ["total"]=> string(1) "0" ["results"]=> array(0) { } }


        Then the size of the array is hinted at the start - 2. So when you check



        if (count($resort_results) == 0 && $resort_results['total'] == 0) :


        The first part is saying if it contains no values, so why bother checking the value if it has no values!



        A more common way is to check if the field is not empty and then check the values...



        if ( !empty($resort_results['total']) && $resort_results['total'] == 0) :






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 16:17









        Nigel RenNigel Ren

        26.6k61833




        26.6k61833























            0














            put three equal when int result



            if (count($resort_results) === 0 && $resort_results['total'] === 0) :






            share|improve this answer
























            • === also check type of values that 0 isn't equal with '0'

              – Mohammad
              Nov 16 '18 at 16:13


















            0














            put three equal when int result



            if (count($resort_results) === 0 && $resort_results['total'] === 0) :






            share|improve this answer
























            • === also check type of values that 0 isn't equal with '0'

              – Mohammad
              Nov 16 '18 at 16:13
















            0












            0








            0







            put three equal when int result



            if (count($resort_results) === 0 && $resort_results['total'] === 0) :






            share|improve this answer













            put three equal when int result



            if (count($resort_results) === 0 && $resort_results['total'] === 0) :







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '18 at 16:12









            Renan Buenos Aires De MoraisRenan Buenos Aires De Morais

            12




            12













            • === also check type of values that 0 isn't equal with '0'

              – Mohammad
              Nov 16 '18 at 16:13





















            • === also check type of values that 0 isn't equal with '0'

              – Mohammad
              Nov 16 '18 at 16:13



















            === also check type of values that 0 isn't equal with '0'

            – Mohammad
            Nov 16 '18 at 16:13







            === also check type of values that 0 isn't equal with '0'

            – Mohammad
            Nov 16 '18 at 16:13




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341569%2fproblems-with-if-equals-0%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()