从多维数组中提取数组

时间:2022-04-25 21:29:56

So here is my array:

所以这是我的数组:

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

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

How can I extract "form_array" as an array?

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

3 个解决方案

#1


2  

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:

实际上你只有一个带有一个元素的简单数组,它是一个字符串,似乎是JSON编码的。要获取其数据,您可以使用以下内容:

// 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.

这些步骤当然可以简化为单行。我只是将它们分开以便于阅读和清晰。

#2


1  

You can try

你可以试试

$array = json_decode($array[0]);
$formArray = $array->form_array;

#3


1  

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

如果您已发布var_dump(arrayname)的结果,那么此代码仅对您有所帮助

$data = $data['form_array'];

else you can go with Sirko's anser

否则你可以和Sirko的anser一起去

#1


2  

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:

实际上你只有一个带有一个元素的简单数组,它是一个字符串,似乎是JSON编码的。要获取其数据,您可以使用以下内容:

// 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.

这些步骤当然可以简化为单行。我只是将它们分开以便于阅读和清晰。

#2


1  

You can try

你可以试试

$array = json_decode($array[0]);
$formArray = $array->form_array;

#3


1  

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

如果您已发布var_dump(arrayname)的结果,那么此代码仅对您有所帮助

$data = $data['form_array'];

else you can go with Sirko's anser

否则你可以和Sirko的anser一起去