$ii = 0; foreach ($xmlres->sto as $sto) { if (++$ii > 2) break; $t = $sto->sta->tit; $i = $sto->sta->cod->ta; }