English 中文(简体)
我如何通过各种价值观来表达
原标题:How do I loop through array of values posted

I m posting an array of ids and want to loop over those values. I m trying the following to populate an array with key/value pairs but it looks like the array is coming out empty.

$arr = array();
foreach($_POST[ ids ] as $id)
{
   $arr[$id] = GetStuff($id);
}

<><>UPDATE: 象阵列一样的眼光是有人用的罚款。 I m试图通过照读echo json_encode(arr)归还阵列内容,但答复是空白。

这里是var($_POST);

  array(1) {
  ["ids"]=>
  array(18) {
    [0]=>
    string(6) "156795"
    [1]=>
    string(6) "156800"
    [2]=>
    string(4) "4292"
    [3]=>
    string(6) "796053"
    [4]=>
    string(6) "660520"
    [5]=>
    string(4) "4293"
    [6]=>
    string(4) "4287"
    [7]=>
    string(6) "488339"
    [8]=>
    string(6) "837701"
    [9]=>
    string(7) "1152093"
    [10]=>
    string(7) "1186434"
    [11]=>
    string(7) "1324432"
    [12]=>
    string(6) "796051"
    [13]=>
    string(6) "144860"
    [14]=>
    string(5) "15065"
    [15]=>
    string(7) "1324434"
    [16]=>
    string(5) "13066"
    [17]=>
    string(4) "6969"
  }
}
问题回答
foreach($_POST[ ids ] AS $i=>$id) {
    //do stuff
}

Don tabe about quotes.

$arr = array();
foreach($_POST[ ids ] as $id)
{
   $arr[$id] = GetStuff($id);
}

Notice Notice Notice

这一工作应当:

foreach($_POST[ ids ] as $id)
{
   $arr[$id] = $_POST[ ids ][$id];
}

如果你只是想要一个与所张贴的婴儿相同的阵列:

$arr = $_POST[ ids ];

除非我误解这个问题。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签