mercredi 15 août 2018

Why is the variable empty inside an if block, but has a value outside of it?

I found something I can't explain. $post_id is set to 9, $bookmarks is an array with [5] => true in it. If I move die($post_id) outside this block and it doesn't matter if I put it before or after, $post_id will contain 9 but inside the block it has neither type nor value. How is it possible?

if ( !in_array($post_id, $bookmarks) ) {
    $bookmarks[$post_id] = true;
    die($post_id);
}

Aucun commentaire:

Enregistrer un commentaire