Problems with if equals 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?
php
add a comment |
'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
1
Because count of$resort_results
isn't0
– Mohammad
Nov 16 '18 at 16:12
add a comment |
'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
'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
php
asked Nov 16 '18 at 16:09
zigojackozigojacko
1,03973061
1,03973061
1
Because count of$resort_results
isn't0
– Mohammad
Nov 16 '18 at 16:12
add a comment |
1
Because count of$resort_results
isn't0
– 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
add a comment |
3 Answers
3
active
oldest
votes
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.
Yes, that is exactly what I was meant to do - I see now, cheers.
– zigojacko
Nov 16 '18 at 16:25
add a comment |
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) :
add a comment |
put three equal when int result
if (count($resort_results) === 0 && $resort_results['total'] === 0) :
===
also check type of values that0
isn't equal with'0'
– Mohammad
Nov 16 '18 at 16:13
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Yes, that is exactly what I was meant to do - I see now, cheers.
– zigojacko
Nov 16 '18 at 16:25
add a comment |
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.
Yes, that is exactly what I was meant to do - I see now, cheers.
– zigojacko
Nov 16 '18 at 16:25
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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) :
add a comment |
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) :
add a comment |
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) :
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) :
answered Nov 16 '18 at 16:17
Nigel RenNigel Ren
26.6k61833
26.6k61833
add a comment |
add a comment |
put three equal when int result
if (count($resort_results) === 0 && $resort_results['total'] === 0) :
===
also check type of values that0
isn't equal with'0'
– Mohammad
Nov 16 '18 at 16:13
add a comment |
put three equal when int result
if (count($resort_results) === 0 && $resort_results['total'] === 0) :
===
also check type of values that0
isn't equal with'0'
– Mohammad
Nov 16 '18 at 16:13
add a comment |
put three equal when int result
if (count($resort_results) === 0 && $resort_results['total'] === 0) :
put three equal when int result
if (count($resort_results) === 0 && $resort_results['total'] === 0) :
answered Nov 16 '18 at 16:12
Renan Buenos Aires De MoraisRenan Buenos Aires De Morais
12
12
===
also check type of values that0
isn't equal with'0'
– Mohammad
Nov 16 '18 at 16:13
add a comment |
===
also check type of values that0
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Because count of
$resort_results
isn't0
– Mohammad
Nov 16 '18 at 16:12