Jump to content

$n = 123; if($child->id == $n) does not work, but if($child->id == "123")


Reymanx3x

Recommended Posts

Hey guys!

 

I have the following strange problem:

 

Listing 1:

echo $n;   // Result is 20167 !

      if($child->id == $n){
      $image = array();
      $image[] = '"' . $child->id . '"';
      $image[] = '"' . $child->name . '"';
      $image[] = '"' . $misc->clean_path($child->file) . '"';
      $image[] = '"' . $child->file_name . '"';
      $image[] = '"' . $child->file_type . '"';
        $image[] = '"' . $path . '"';
      
      $images[] = implode("\t", $image);
      }

 

The if-statement is not true... so probably there's no $child->id with value 20167.... but watch this:

 

Listing 2:

if($child->id == 20167){
      $image = array();
      $image[] = '"' . $child->id . '"';
      $image[] = '"' . $child->name . '"';
      $image[] = '"' . $misc->clean_path($child->file) . '"';
      $image[] = '"' . $child->file_name . '"';
      $image[] = '"' . $child->file_type . '"';
        $image[] = '"' . $path . '"';
      
      $images[] = implode("\t", $image);
      }

 

Now with the hard coded value 20167 the statement is true and gives one result....

 

Strange, isn't it?

 

I placed the following three functions/test direct before the if-statement:

var_dump($n);    
Result: NULL


echo $n
Result: 20167 

echo "{$n}";
Result:

 

 

I tested one function at a time.

 

 

How can this happen?

 

 

Thanks to all! :-)

 

Probably you need the whole code of the function:

function scanImages($id,$path,$picid) {
    global $server, $images, $misc;

    $childs = $server->children($id, "O.sort_order", "", 0);
   
  
    for ($i = 0; $i < count($childs->results); $i++) {

  $child = $server->object($childs->results[$i]);
      switch ($child->type) {
    case "183":

    if($child->id == $picid){
	  $image = array();
	  $image[] = '"' . $child->id . '"';
	  $image[] = '"' . $child->name . '"';
	  $image[] = '"' . $misc->clean_path($child->file) . '"';
	  $image[] = '"' . $child->file_name . '"';
	  $image[] = '"' . $child->file_type . '"';
  		  $image[] = '"' . $path . '"';
	  
	  $images[] = implode("\t", $image);
	  }
	  break;
	case "14":		 
	  scanImages($child->id,$path."/".$child->name);
      break;
    default:
      };
    }; 
  }
   
  scanImages(181,"Bilder", 20167);

 

 

Sorry, thread can be closed!

 

The error was, that I forgot to forward the third argument of the function "scanImages" in the inner self-call:

 

if($child->id == $picid){

  $image = array();

  $image[] = '"' . $child->id . '"';

  $image[] = '"' . $child->name . '"';

  $image[] = '"' . $misc->clean_path($child->file) . '"';

  $image[] = '"' . $child->file_name . '"';

  $image[] = '"' . $child->file_type . '"';

    $image[] = '"' . $path . '"';

 

  $images[] = implode("\t", $image);

  }

  break;

case "14":

scanImages($child->id,$path."/".$child->name);

      break;

    default:

      };

 

 

Thanks to everybody!

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.