Array_search ignoring the first element [closed]

In PHP, the number 0 is interpreted as false-ish.
Your if-statement asks for a true-ish condition like this:

If the result of the array_search function is interpreted as true-ish, THEN do the stuff

which means if the result is 0, it is interpreted as false, and the code doesn’t run.

What to do?

Use the identical operator for false like this to check for your wanted condition. Change your if-statement like this:

if ( !( false === array_search( $currentpage, $yearlyarchives, true) ) ){
     ?> en el <?php echo get_query_var('year');
}

The code will then run if the result of the array search is not identical to false (array_search will return false if the needle is not found).

Happy Coding!