duckstar Posted March 22, 2010 Share Posted March 22, 2010 Hi there, for some reason thoe following isn't working at all.. Anyone know why ? $temp1 = $nonRBProducts[$counteri][3]; $temp1 * 1; $temp2 = $RBProducts[$counterr][3]; $temp2 * 1; $temp3 = $temp1 + $temp2; $temp1 = 9 $temp2 = 4 $temp3 = "" Anyone know why ? Cheers Link to comment https://forums.phpfreaks.com/topic/196102-very-simple-adding-not-working/ Share on other sites More sharing options...
harristweed Posted March 22, 2010 Share Posted March 22, 2010 uhhmm This displays the correct values: <?php $temp1=9; $temp2=4; //$temp1 = $nonRBProducts[$counteri][3]; $temp1 * 1; //$temp2 = $RBProducts[$counterr][3]; $temp2 * 1; $temp3 = $temp1 + $temp2; echo"temp1 = $temp1<br />temp2 = $temp2<br />temp3 = $temp3<br />"; ?> Are you sure the variables $nonRBProducts[$counteri][3]; and $RBProducts[$counterr][3]; contain a value? And what is the purpose of attempting to multiplying by 1? If that's what you want to do because $temp2 * 1; wont do anything! Link to comment https://forums.phpfreaks.com/topic/196102-very-simple-adding-not-working/#findComment-1029900 Share on other sites More sharing options...
slurpee Posted March 22, 2010 Share Posted March 22, 2010 Well first of all, what are you doing in the commented lines below? $temp1 = $nonRBProducts[$counteri][3]; $temp1 * 1; ///<--- What are you doing here? This won't result in the value of $temp1 changing in any way. $temp2 = $RBProducts[$counterr][3]; $temp2 * 1; ///<--- And here? $temp3 = $temp1 + $temp2; Link to comment https://forums.phpfreaks.com/topic/196102-very-simple-adding-not-working/#findComment-1029902 Share on other sites More sharing options...
duckstar Posted March 22, 2010 Author Share Posted March 22, 2010 Thanks for the replys die($nonRBProducts[$counteri][3]); Returns 9 die($RBProducts[$counterr][3]); Returns 4 $temp2 * 1; I know this doesn't change the value. I did this to try and force PHP to see it as a INT so that it would add correctly on the next line. die($temp1."+".$temp2."=".$temp3); Now returns = "9+4=13" but $temp1 = $nonRBProducts[$counteri][3]; $temp1 * 1; $temp2 = $RBProducts[$counterr][3]; $temp2 * 1; $temp3 = $temp1 + $temp2; //die($temp1."+".$temp2."=".$temp3); $mergedAdviceNotes[$mergedIndex][3] = $temp3; die($mergedAdviceNotes[$mergedIndex][3]); This returns nothing... Link to comment https://forums.phpfreaks.com/topic/196102-very-simple-adding-not-working/#findComment-1029905 Share on other sites More sharing options...
duckstar Posted March 22, 2010 Author Share Posted March 22, 2010 ....I have no idea why but this works.. die($mergedAdviceNotes[$mergedIndex][3]." is the value"); and returns : 13 is the value Link to comment https://forums.phpfreaks.com/topic/196102-very-simple-adding-not-working/#findComment-1029907 Share on other sites More sharing options...
scvinodkumar Posted March 22, 2010 Share Posted March 22, 2010 i think the only reason is the array doesn't exist($mergedAdviceNotes), check either spelling mistakes or two dimensional array exists.. or check like this instead of die echo $mergedAdviceNotes[$mergedIndex][3]; Link to comment https://forums.phpfreaks.com/topic/196102-very-simple-adding-not-working/#findComment-1029916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.