Jump to content

Wierdest thing i have ever seen!


glenelkins

Recommended Posts

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

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";
}

?>

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

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.