dphw5101
2012-10-09 09:51
浏览 59
已采纳

从多维数组中提取数组

So here is my array:

array(1) { [0]=> string(79) "{"form_array":{"element1":"value1","element2":"value2","element3":"value3"}}" }

How can I extract "form_array" as an array?

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

所以这是我的数组:

数组( 1){[0] => string(79)“{”form_array“:{”element1“:”value1“,”element2“:”value2“,”element3“:”value3“}}”}

如何将“form_array”提取为数组?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duankangpazhuo0347 2012-10-09 09:54
    已采纳

    You actually have just a simple array with one element, which is a string, that seems to be JSON encoded. To get its data, you may use the following:

    // get the string
    $data = $array[0];
    
    // decode the content
    $data = json_decode( $data, true );
    
    // get the sub array
    $data = $data['form_array'];
    

    The steps may of course be simplified into a single row. I just separated them for readability and clarity.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doupo5861 2012-10-09 09:53

    You can try

    $array = json_decode($array[0]);
    $formArray = $array->form_array;
    
    评论
    解决 无用
    打赏 举报
  • dongzhi1851 2012-10-09 09:58

    If you have posted the result of var_dump(arrayname), then this code only will help you

    $data = $data['form_array'];
    

    else you can go with Sirko's anser

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题