glenelkins Posted April 9, 2009 Share Posted April 9, 2009 Hi This is so wierd! I have an array like this for example: <?php $n = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $n = count ( $array ); // 16 echo "$n"; // 16; $i = 16; if ( $n > $i ) { echo 'n is bigger'; } ?> Now, $n and $i are the same! but it still does the echo after the If....what?? doesnt make sense (please use tags when posting code) Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/ Share on other sites More sharing options...
redarrow Posted April 9, 2009 Share Posted April 9, 2009 you need this then don't you. <?php $n = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $n = count ( $array ); // 16 echo "$n"; // 16; $i = 16; if ( $n > $i && $n !=$i ) { echo 'n is bigger'; } ?> Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805419 Share on other sites More sharing options...
glenelkins Posted April 9, 2009 Author Share Posted April 9, 2009 no that doesnt work either if i actually manually set both variables to 16 , then is works. Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805421 Share on other sites More sharing options...
glenelkins Posted April 9, 2009 Author Share Posted April 9, 2009 another strange thing, if i put some code, like die() after the IF, then the if works fine. wtf is going on with that Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805422 Share on other sites More sharing options...
redarrow Posted April 9, 2009 Share Posted April 9, 2009 this does work, if the number is bigger && it not the same. <?php $n = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $n = count($n); $i = 16; if ( $n > $i && $n !=$i ) { echo 'n is bigger'; }else{ echo"not bigger"; } ?> this works as well with a or !! <?php $n = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $n = count($n); $i = 16; if ( $n > $i || $n !=$i ) { echo 'n is bigger'; }else{ echo"not bigger"; } ?> Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805424 Share on other sites More sharing options...
kenrbnsn Posted April 9, 2009 Share Posted April 9, 2009 Make sure you're array and variable holding the count of the array are not the same. Instead of <?php $n = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $n = count($n); ?> do <?php $x = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $n = count($x); ?> Ken Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805432 Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2009 Share Posted April 9, 2009 There's no way the code you are executing is the same as the posted code. $n = count ( $array ); // 16 is using the wrong array variable. I'm going to guess that you have a second array named $array that you did not post. We cannot help you unless you post the actual code that corresponds to the results you are getting. Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805451 Share on other sites More sharing options...
redarrow Posted April 9, 2009 Share Posted April 9, 2009 I get it now, I think he picking on php, and looking at draw backs in programming in php. also as pointed out your using the same variable name with count $n. that the real problem. Link to comment https://forums.phpfreaks.com/topic/153310-wierdest-thing-i-have-ever-seen/#findComment-805455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.