I don't think you've posted your code accurately: you said everything is working, but on my screen it doesn't make sense. I presume you want four fieldlists labeled "One," "Too," etc. You can't accomplish this with the code you posted: you print the labels first all at once, the fieldlists second all at once; thus, all of the labels are clustered together on top of the fieldlists.
You've made this much, much harder than it needs to be.
$keys= array_keys($layout);
$total=count($keys);
You don't need this. You can get the same result with
$total = count($layout);
Your first foreach loop echos values but on the screen they're not attached to anything. They're just sorta hangin' out there. Lose it. You don't need it.
You don't need prev_key and next_key. If what you display is entirely dependent upon the index at the time, you just need to know that index. For that you can do this in your second foreach loop:
foreach ($layout as $k => $v) {
$k is your index.
if($prev_key!='1'):
...
if($next_key!=''):
If your goal is to put buttons in a certain order, and that order is determined arbitrarily using the layout array (i.e. if idx = 1 do buttonx, if idx = 2 do buttony), you don't need these variables or checks.
Your entire code can be written as an array definition and single foreach loop, like so:
$layout = array('One', 'Too', 'Three', 'Four');
$total = count($layout);
foreach($layout as $k => $value) { // $k is your index
?>
<form action="myaction" method="post" id="submit_form" class="manager-form" enctype="multipart/form-data">
<fieldset tabindex="-1" id="step-<?php echo esc_attr($value); ?>">
<!-- fieldset is a block level element, so you don't need the div tag -->
<!-- div class="ere-step-nav" -->
<?php if($k > 0): ?>
<!-- only show previous when we're not on the zero-th element -->
<button class="btn-prev" aria-controls="step-<?php echo esc_attr($k); ?>"
type="button" title="<?php esc_attr_e('Previous') ?>"><i class="fa fa-angle-left"></i><span><?php esc_html_e('Previous') ?></span></button>
<?php endif; ?>
<!-- this button shows all the time -->
<button class="btn-all" type="button" title="<?php esc_attr_e('All Fields') ?>"><?php esc_html_e('All') ?></button>
<?php if ($k < ($total - 1)): ?>
<!-- only show the next button when we're not on the last element -->
<button class="btn-next" aria-controls="step-<?php echo esc_attr($k); ?>"
type="button" title="<?php esc_attr_e('Next') ?>"><span><?php esc_html_e('Next') ?></span><i class="fa fa-angle-right"></i></button>
<?php endif; ?>
<!-- the submit button shows all the time -->
<input type="submit" name="submit_button" class="btn-submit" value="Submit>"/>
<!-- /div -->
</fieldset>
</form>
<?php
}
Questions?