0

我有这样的帖子价值。它存储在$_POST. 现在,我需要删除或取消设置最后一个数组值,即[submit] => Add. 当我签入 SOF 时,他们要求我使用array_pop. 但这没有用。任何帮助。

我的输出:

    [56-1] => 0
    [56-2] => 0
    [56-3] => 0
    [submit] => Add

预期输出:

        [56-1] => 0
        [56-2] => 0
        [56-3] => 0

编辑:

这是我的代码

    <?php 
    $my_array = $_POST;
    foreach($my_array as $key=>$value){
    array_pop($my_array);
    unset($key['submit']);
    }
    print_r($my_array);
    ?>

谢谢,

金兹

4

3 回答 3

2
<?php

unset($_POST['submit']);

?>
于 2014-03-17T07:32:22.517 回答
1
$my_array = $_POST;

不需要使用循环。你应该做:

unset($my_array['submit']);

于 2014-03-17T07:32:26.047 回答
0

试试这样:

<?php 
    $my_array = $_POST;
    foreach($my_array as $key=>$value){ // this foreach will eventually pop ALL your items
        echo "foreach is now at value: $value<br/>"; // remove this line if you remove the foreach
        echo "but now removing the last value of array (pop), which is value: "
        echo array_pop($my_array) . "<br/>";
        echo "done<br/>";
        // unset($key['submit']); // remove this line. this is foobar. $key['submit'] will never exist.
    }
    print_r($my_array); // with the foreach, this will print nothing (empty). without the foreach, only the last line would print...
?>
于 2014-03-17T07:35:07.263 回答