Associative array values showing as strings instead of int
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I apologize if this was answered, I did look for a bit but couldn't find anything.
I need to add the same values from two different arrays. I have...
$monData = array([mjones] => 50,[total] => 50)
$tueData = array([mjones] => 50,[total] => 50)
I need to put the sum of the [total]'s in to an email, but when I do
<html>'.$monData['total] + $tueData['total].'</html>
I get an error about a non-numeric value. I'm sure this is easy and I'm overlooking something stupid, but I couldn't find anything to answer it without rebuilding the entire arrays which would take a lot of work.
Edit:
Sorry about the syntax errors. The error isn't the arrays it was just summing the values of them. I can see why it was misleading though, I apologize.
php arrays
add a comment |
I apologize if this was answered, I did look for a bit but couldn't find anything.
I need to add the same values from two different arrays. I have...
$monData = array([mjones] => 50,[total] => 50)
$tueData = array([mjones] => 50,[total] => 50)
I need to put the sum of the [total]'s in to an email, but when I do
<html>'.$monData['total] + $tueData['total].'</html>
I get an error about a non-numeric value. I'm sure this is easy and I'm overlooking something stupid, but I couldn't find anything to answer it without rebuilding the entire arrays which would take a lot of work.
Edit:
Sorry about the syntax errors. The error isn't the arrays it was just summing the values of them. I can see why it was misleading though, I apologize.
php arrays
I can tell you it has nothing to do with the difference between50
and'50'
, PHP doesn't care about those things.I get an error about a non-numeric value
Why not post the full error
– ArtisticPhoenix
Jan 4 at 0:48
First you should fix all those syntax errors. If your next question is "what syntax errors?" then you also need to turnerror_reporting
on.
– Sammitch
Jan 4 at 0:54
This is not my exact code, I quickly retyped it to give an idea, and it seems to have changed the location of some commas. But I will check it out, thanks.
– mobirae
Jan 4 at 0:58
@ArtisticPhoenix that is pretty much the full error. The only other part it mentions is the file name and the line number. Thanks for your comments in the other answers.
– mobirae
Jan 4 at 1:12
add a comment |
I apologize if this was answered, I did look for a bit but couldn't find anything.
I need to add the same values from two different arrays. I have...
$monData = array([mjones] => 50,[total] => 50)
$tueData = array([mjones] => 50,[total] => 50)
I need to put the sum of the [total]'s in to an email, but when I do
<html>'.$monData['total] + $tueData['total].'</html>
I get an error about a non-numeric value. I'm sure this is easy and I'm overlooking something stupid, but I couldn't find anything to answer it without rebuilding the entire arrays which would take a lot of work.
Edit:
Sorry about the syntax errors. The error isn't the arrays it was just summing the values of them. I can see why it was misleading though, I apologize.
php arrays
I apologize if this was answered, I did look for a bit but couldn't find anything.
I need to add the same values from two different arrays. I have...
$monData = array([mjones] => 50,[total] => 50)
$tueData = array([mjones] => 50,[total] => 50)
I need to put the sum of the [total]'s in to an email, but when I do
<html>'.$monData['total] + $tueData['total].'</html>
I get an error about a non-numeric value. I'm sure this is easy and I'm overlooking something stupid, but I couldn't find anything to answer it without rebuilding the entire arrays which would take a lot of work.
Edit:
Sorry about the syntax errors. The error isn't the arrays it was just summing the values of them. I can see why it was misleading though, I apologize.
php arrays
php arrays
edited Jan 4 at 1:10
mobirae
asked Jan 4 at 0:45
mobiraemobirae
14
14
I can tell you it has nothing to do with the difference between50
and'50'
, PHP doesn't care about those things.I get an error about a non-numeric value
Why not post the full error
– ArtisticPhoenix
Jan 4 at 0:48
First you should fix all those syntax errors. If your next question is "what syntax errors?" then you also need to turnerror_reporting
on.
– Sammitch
Jan 4 at 0:54
This is not my exact code, I quickly retyped it to give an idea, and it seems to have changed the location of some commas. But I will check it out, thanks.
– mobirae
Jan 4 at 0:58
@ArtisticPhoenix that is pretty much the full error. The only other part it mentions is the file name and the line number. Thanks for your comments in the other answers.
– mobirae
Jan 4 at 1:12
add a comment |
I can tell you it has nothing to do with the difference between50
and'50'
, PHP doesn't care about those things.I get an error about a non-numeric value
Why not post the full error
– ArtisticPhoenix
Jan 4 at 0:48
First you should fix all those syntax errors. If your next question is "what syntax errors?" then you also need to turnerror_reporting
on.
– Sammitch
Jan 4 at 0:54
This is not my exact code, I quickly retyped it to give an idea, and it seems to have changed the location of some commas. But I will check it out, thanks.
– mobirae
Jan 4 at 0:58
@ArtisticPhoenix that is pretty much the full error. The only other part it mentions is the file name and the line number. Thanks for your comments in the other answers.
– mobirae
Jan 4 at 1:12
I can tell you it has nothing to do with the difference between
50
and '50'
, PHP doesn't care about those things. I get an error about a non-numeric value
Why not post the full error– ArtisticPhoenix
Jan 4 at 0:48
I can tell you it has nothing to do with the difference between
50
and '50'
, PHP doesn't care about those things. I get an error about a non-numeric value
Why not post the full error– ArtisticPhoenix
Jan 4 at 0:48
First you should fix all those syntax errors. If your next question is "what syntax errors?" then you also need to turn
error_reporting
on.– Sammitch
Jan 4 at 0:54
First you should fix all those syntax errors. If your next question is "what syntax errors?" then you also need to turn
error_reporting
on.– Sammitch
Jan 4 at 0:54
This is not my exact code, I quickly retyped it to give an idea, and it seems to have changed the location of some commas. But I will check it out, thanks.
– mobirae
Jan 4 at 0:58
This is not my exact code, I quickly retyped it to give an idea, and it seems to have changed the location of some commas. But I will check it out, thanks.
– mobirae
Jan 4 at 0:58
@ArtisticPhoenix that is pretty much the full error. The only other part it mentions is the file name and the line number. Thanks for your comments in the other answers.
– mobirae
Jan 4 at 1:12
@ArtisticPhoenix that is pretty much the full error. The only other part it mentions is the file name and the line number. Thanks for your comments in the other answers.
– mobirae
Jan 4 at 1:12
add a comment |
3 Answers
3
active
oldest
votes
Your problem is due to operator precedence, the .
and +
operators have equal precedence and so your expression is being interpreted as this:
(('<html>' . $monData['total']) + $tueData['total']) . '</html>'
The first operation yields a string, which you are then trying to add to a number with +
, which gives you a non-numeric value error. With your specific values, it's like trying to add '<html>50' + 50
.
You need to rewrite your code as
<html>'.($monData['total'] + $tueData['total']).'</html>
2
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like'<html>50' + 50
because of the op order.
– ArtisticPhoenix
Jan 4 at 0:51
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
|
show 1 more comment
Try this one:
<html>'.(intVal($monData['total]) + intVal($tueData['total])).'</html>
add a comment |
Correct code:
$monData = array('mjones' => 50, 'total' => 50);
$tueData = array('mjones' => 50, 'total' => 50);
Then in html:
<html><?php echo ($monData['total'] + $tueData['total']); ?></html>
or:
<?php echo '<html>'. ($monData['total'] + $tueData['total']) . '</html>'; ?>
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%2f54031781%2fassociative-array-values-showing-as-strings-instead-of-int%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
Your problem is due to operator precedence, the .
and +
operators have equal precedence and so your expression is being interpreted as this:
(('<html>' . $monData['total']) + $tueData['total']) . '</html>'
The first operation yields a string, which you are then trying to add to a number with +
, which gives you a non-numeric value error. With your specific values, it's like trying to add '<html>50' + 50
.
You need to rewrite your code as
<html>'.($monData['total'] + $tueData['total']).'</html>
2
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like'<html>50' + 50
because of the op order.
– ArtisticPhoenix
Jan 4 at 0:51
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
|
show 1 more comment
Your problem is due to operator precedence, the .
and +
operators have equal precedence and so your expression is being interpreted as this:
(('<html>' . $monData['total']) + $tueData['total']) . '</html>'
The first operation yields a string, which you are then trying to add to a number with +
, which gives you a non-numeric value error. With your specific values, it's like trying to add '<html>50' + 50
.
You need to rewrite your code as
<html>'.($monData['total'] + $tueData['total']).'</html>
2
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like'<html>50' + 50
because of the op order.
– ArtisticPhoenix
Jan 4 at 0:51
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
|
show 1 more comment
Your problem is due to operator precedence, the .
and +
operators have equal precedence and so your expression is being interpreted as this:
(('<html>' . $monData['total']) + $tueData['total']) . '</html>'
The first operation yields a string, which you are then trying to add to a number with +
, which gives you a non-numeric value error. With your specific values, it's like trying to add '<html>50' + 50
.
You need to rewrite your code as
<html>'.($monData['total'] + $tueData['total']).'</html>
Your problem is due to operator precedence, the .
and +
operators have equal precedence and so your expression is being interpreted as this:
(('<html>' . $monData['total']) + $tueData['total']) . '</html>'
The first operation yields a string, which you are then trying to add to a number with +
, which gives you a non-numeric value error. With your specific values, it's like trying to add '<html>50' + 50
.
You need to rewrite your code as
<html>'.($monData['total'] + $tueData['total']).'</html>
edited Jan 4 at 0:56
answered Jan 4 at 0:49
NickNick
39k132443
39k132443
2
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like'<html>50' + 50
because of the op order.
– ArtisticPhoenix
Jan 4 at 0:51
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
|
show 1 more comment
2
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like'<html>50' + 50
because of the op order.
– ArtisticPhoenix
Jan 4 at 0:51
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
2
2
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like
'<html>50' + 50
because of the op order.– ArtisticPhoenix
Jan 4 at 0:51
I was just gonna say there are some syntax errors in the original (probably just from creating the question) but now they are gone (in the answer at least)... The only thing I would add is that its like
'<html>50' + 50
because of the op order.– ArtisticPhoenix
Jan 4 at 0:51
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
@ArtisticPhoenix I've corrected OPs syntax errors (I didn't notice them until SO formatted my answer). I've assumed they were copying errors. Either way, the rewrite code should give the correct result.
– Nick
Jan 4 at 0:53
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
It's good answer, I was just saying...
– ArtisticPhoenix
Jan 4 at 0:54
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
@ArtisticPhoenix I upvoted your comment... I agree with it completely. I've included your suggested note in an edit.
– Nick
Jan 4 at 0:56
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
Kool, Id upvote the answer again if I could ... Cheers!
– ArtisticPhoenix
Jan 4 at 0:57
|
show 1 more comment
Try this one:
<html>'.(intVal($monData['total]) + intVal($tueData['total])).'</html>
add a comment |
Try this one:
<html>'.(intVal($monData['total]) + intVal($tueData['total])).'</html>
add a comment |
Try this one:
<html>'.(intVal($monData['total]) + intVal($tueData['total])).'</html>
Try this one:
<html>'.(intVal($monData['total]) + intVal($tueData['total])).'</html>
answered Jan 4 at 0:48
aidinMCaidinMC
1,04421225
1,04421225
add a comment |
add a comment |
Correct code:
$monData = array('mjones' => 50, 'total' => 50);
$tueData = array('mjones' => 50, 'total' => 50);
Then in html:
<html><?php echo ($monData['total'] + $tueData['total']); ?></html>
or:
<?php echo '<html>'. ($monData['total'] + $tueData['total']) . '</html>'; ?>
add a comment |
Correct code:
$monData = array('mjones' => 50, 'total' => 50);
$tueData = array('mjones' => 50, 'total' => 50);
Then in html:
<html><?php echo ($monData['total'] + $tueData['total']); ?></html>
or:
<?php echo '<html>'. ($monData['total'] + $tueData['total']) . '</html>'; ?>
add a comment |
Correct code:
$monData = array('mjones' => 50, 'total' => 50);
$tueData = array('mjones' => 50, 'total' => 50);
Then in html:
<html><?php echo ($monData['total'] + $tueData['total']); ?></html>
or:
<?php echo '<html>'. ($monData['total'] + $tueData['total']) . '</html>'; ?>
Correct code:
$monData = array('mjones' => 50, 'total' => 50);
$tueData = array('mjones' => 50, 'total' => 50);
Then in html:
<html><?php echo ($monData['total'] + $tueData['total']); ?></html>
or:
<?php echo '<html>'. ($monData['total'] + $tueData['total']) . '</html>'; ?>
edited Jan 4 at 1:36
answered Jan 4 at 0:49
dev101dev101
78611324
78611324
add a comment |
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%2f54031781%2fassociative-array-values-showing-as-strings-instead-of-int%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
I can tell you it has nothing to do with the difference between
50
and'50'
, PHP doesn't care about those things.I get an error about a non-numeric value
Why not post the full error– ArtisticPhoenix
Jan 4 at 0:48
First you should fix all those syntax errors. If your next question is "what syntax errors?" then you also need to turn
error_reporting
on.– Sammitch
Jan 4 at 0:54
This is not my exact code, I quickly retyped it to give an idea, and it seems to have changed the location of some commas. But I will check it out, thanks.
– mobirae
Jan 4 at 0:58
@ArtisticPhoenix that is pretty much the full error. The only other part it mentions is the file name and the line number. Thanks for your comments in the other answers.
– mobirae
Jan 4 at 1:12