douzi8127 2016-01-30 11:17
浏览 257
已采纳

PHP从post数组中获取值

I'm posting an array from a html form with the following input-tag:

<input type="text" name="new_service[1]['category']">

I get this array:

Array
(
    [1] => Array
        (
            ['category'] => 1
            ['description'] => asdasd
            ['price'] => asdasd
            ['time'] => 1
        )

)

When I try to get the category value with

echo $_POST['new_service'][1]['category']; 

I get this error message:

Notice: Undefined index: category

What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • douhongxie5436 2016-01-30 11:33
    关注

    The index you create this way is not category but 'category' i.e. you create an index that also has single quotes.

    So to echo what you want you should use:

    echo $_POST['new_service'][1]["'category'"];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部