Print $_POST variable name along with value

前端 未结 4 666
既然无缘
既然无缘 2020-11-29 05:51

I have a POST in PHP for which I won\'t always know the names of the variable fields I will be processing.

I have a function that will loop through the values (howev

4条回答
  •  不知归路
    2020-11-29 06:34

    You can have the foreach loop show the index along with the value:

    foreach ($_POST as $key => $entry)
    {
         print $key . ": " . $entry . "
    "; }

    As to the array checking, use the is_array() function:

    foreach ($_POST as $key => $entry)
    {
         if (is_array($entry)) {
            foreach($entry as $value) {
               print $key . ": " . $value . "
    "; } } else { print $key . ": " . $entry . "
    "; } }

提交回复
热议问题