Ad ogni ciclo tiri via 2 elementi dall'array, uno nell'if e uno nell'echo.
Devi fare solo un array_shift() ad ogni ciclo, così
Codice PHP:
$pila = array("2""2""3""5");
$num count($pila);
for(
$x=1$x <= $num$x++)
{
    
$temp array_shift($pila);
    if (
$temp '5'){
        echo 
'<strong>'.$temp.'</strong> ='.$x.'<br>';
    }else{
        echo 
$temp.' ='.$x.'<br>';
    }