2015-01-05 23 views
0

遍历数组我有一个数组像这样如何在PHP

$steps = explode("[;;]",$str); 

所以$步骤认为我必须使用显示在PHP中的步/步程序价值。

数组看起来像这样

$steps = array('corredores' , 'something' , 'something'...and so one); 

我试图根据存储阵列中的第一步,我做这样的事情

switch($steps[0]){ 
    case 'categorias' : 
    include 'obj/categorias.php'; 
       //$step='categorias'; 
       break; 
    case 'corredores': 
    include 'obj/corredores.php'; 
       //$step='corredores'; 
       break; 
    case 'monedas': 
    include 'obj/monedas.php'; 
       //$step='monedas'; 
       break; 
    case 'location': 
    include 'obj/location.php'; 
       //$step='location'; 
       break; 
    default: 
    break; 
} 

//这里的值显示形式我试图匹配下一个数组中的值,我将在每个步骤中保存此后期值

if(isset($_POST['next'])) 
{ 
include 'obj/'.$_POST["next"].'php'; 
       //$step='categorias'; 
       break; 

} 
else { 


} 

所以,当我点击每个文件的下一个按钮,它应与该数组中的下一个值,并显示相关文件

每一个文件的HTML内容有以下结构

<form method="post" action="./index.php" name="form_name"> 
<table><tr><th>Some Name</td></tr> 
<tr><td><input type="submit" value="next"></td></tr></table> 

    <input type="hidden" name="next" value="<?php //here i will add the value for next ?>"> 
</form> 

任何一个可以给我一些建议

+0

你的$ steps变量实际上是怎样的? –

+0

@NitsanBaleli请检​​查我已更新的问题 – Vikram

+0

每次打印表格时,隐藏输入的值应该是$ steps [current + 1]。使用Key()函数 – briosheje

回答

1

根据我的理解,您需要使用POST var搜索数组,然后在input标签的value属性中回显下一个值。

<?php 
$key=0; 
if(isset($_POST['next'])){ 
    include 'obj/'.$_POST["next"].'php'; 
    $key = array_search($_POST["next"], $steps); 
    if($key !== false) $key++; 
    if($key==count($steps)) $key=0; 
     //if post contains last element then set $key to first OR do whatever you want 
    break; 
} 
else { } 
?> 

<input type="hidden" name="next" value="<?php echo $steps[$key]; ?>">