douzi8127
2016-01-30 19:17
浏览 186
已采纳

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?

图片转代码服务由CSDN问答提供 功能建议

我正在使用以下输入标记从html表单发布数组: \ n

 &lt; input type =“text”name =“new_service [1] ['category']”&gt; 
   
 
 

我得到了这个 数组:

 数组
(
 [1] =&gt;数组
(
 ['category'] =&gt; 1 
 ['description']  =&gt; asdasd 
 ['price'] =&gt; asdasd 
 ['time'] =&gt; 1 
)
 
)
   
 
 

当我尝试使用

  echo $ _POST ['new_service'] [1] ['category']获取类别值时;  
   
 
 

我收到以下错误消息:

 注意:未定义的索引:category 
  <  / pre> 
 
 

我做错了什么?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douhongxie5436 2016-01-30 19: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'"];

    点赞 评论
  • douping3427 2016-01-30 19:41

    Just use $_POST['new_service']; then loop

    点赞 评论

相关推荐 更多相似问题