本文介绍了获取$ i的值,顺序不受影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  for($ i = 0; $ i  {
//一些输出ommited

< td>< input type ='submit'value ='Purchase'name ='$ name [$ i]'>< / td>< / tr>;
}



现在,一旦按钮被点击,这就是我应该显示的。



pre $ if(isset($ _ REQUEST ['name1'])){echo'name1 selected';}
if(isset($ _ REQUEST ['name2 ')){echo'name2 selected';}
if(isset($ _ REQUEST ['name3'])){echo'name3 selected;}
if(isset($ _ REQUEST ['name4如果(isset($ _ REQUEST ['name5'])){echoname5 selected;}
if(isset($ _ REQUEST ['name6' '])){echoname6 selected;}

禁用任何名称如果name3被禁用,序列/排序 $ i 会改变。我无法显示所需的参数。 $ i 。



例如,我想显示name3禁用:

pre $ if(isset $ _REQUEST ['name4'])){
echo$ name [4] selected,kind是$ kind [4] kind和type是$ type [4];
}

与name3禁用,name4将显示来自name5的值



2:

如何使用$ name [$ i]获取Request的值
$ b $ {$ b pre $ for循环(){
if(isset($ _ REQUEST ['$ name [$ i]'])){echoname1 selected;}

$ / code>

帮助我设置一个算法来获取 $的值所以即使订单受到干扰,我也应该知道 $ i 带有哪个值。


<首先,你必须将 $ i 连接到 name ($ i = 0; $ i< count($ name); $ i ++)获得唯一名称:

pre $
{
echo'< td>< / td>< / tr>< input type ='submit'value ='Purchase'name ='$ name。 ;如果 $ name






$是名字,那么你将得到name1,name2,name3等。

然后你可以 print_r($ _ REQUEST );以查看提交的项目。

您不需要for循环来查看哪些项目已设置,但是如果要循环访问REQUEST数组,您可以执行像这样:

$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $如果('名字' == substr($ post_var,0,4))
{
echo $ post_var。 '';




$结果:


for ($i = 0; $i < count($name); $i++)
   {
    //some output ommited

        <td><input type='submit' value='Purchase' name='$name[$i]'></td></tr>";
    }

Now once the button is clicked, this is what I should be displaying.

if (isset($_REQUEST['name1'])) {echo "name1 selected";}
if (isset($_REQUEST['name2'])) {echo "name2 selected";}
if (isset($_REQUEST['name3'])) {echo "name3 selected";}
if (isset($_REQUEST['name4'])) {echo "name4 selected";}
if (isset($_REQUEST['name5'])) {echo "name5 selected";}
if (isset($_REQUEST['name6'])) {echo "name6 selected";}

I have option in the db to enable or disable any name. If name3 is disabled , the sequence/ordering of $i will change.and I am not able to display the required parameter w.r.t $i.

For exmaple I want to display , with name3 disabled:

if (isset($_REQUEST['name4'])) {
    echo "$name[4] selected, kind is $kind[4] kind and type is $type[4]";
}

with name3 disabled , name4 will display values from name5

2:

How to get the values of Request with $name[$i]

for loop () {
    if (isset($_REQUEST['$name[$i]'])) {echo "name1 selected";}
}

Help me device an algo to get the values of $i, so that even if the order is disturbed , i should know $i is carrying which value.

解决方案

First you have to concat $i to name to get unique names:

for ($i = 0; $i < count($name); $i++)
{
   echo "<td><input type='submit' value='Purchase' name='$name . $i'></td></tr>";
}

If $name is "name" then you will get "name1", "name2", "name3", etc.

Then you can print_r($_REQUEST); to see the items submitted.

You do not need a for loop to see which of the items is set, but if you want to loop through the REQUEST array you could do something like this:

foreach($_REQUEST as $post_var)
{
    if('name' == substr($post_var, 0, 4))
    {
        echo $post_var . ' ';
    }
}

Result:

这篇关于获取$ i的值,顺序不受影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 00:53