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! :-)

 

Link to comment
Share on other sites

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);

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.