Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多维数组展平_Php_Arrays_Multidimensional Array - Fatal编程技术网

Php 多维数组展平

Php 多维数组展平,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我正在努力实现这一目标。。也许有人知道我如何做到这一点,我只是做了一部分,我还研究了php和drupal函数 这是完整的图像 field_new(Arr…)必须变成['value']=string(11111)您的输入数组: ... 0{ data{ nid => 1 vid => 1 type => article field_new{ und{

我正在努力实现这一目标。。也许有人知道我如何做到这一点,我只是做了一部分,我还研究了php和drupal函数

这是完整的图像


field_new(Arr…)必须变成['value']=string(11111)

您的输入数组:

...
0{
    data{
        nid => 1
        vid => 1
        type => article
        field_new{
            und{
                0{
                    value => 11111
                }
            }
        }
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        field_new{
            und{
                0{
                    value => 33333
                }
            }
        }
    }
}
...
0{
    data{
        nid => 1
        vid => 1
        type => article
        value => 11111
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        value => 33333
    }
}
<?php

$loop_count = count($input_arr);
for($i=0;$i<loop_count;$i++){
    //copy the value to the desired place
    $input_arr[$i]["data"]["value"] = $input_arr[$i]["data"]["field_new"]["und"][0]["value"];

    //delete the unwanted portion
    unset($input_arr[$i]["data"]["field_new"]);
} // for loops ENDS

?>
您想要的阵列:

...
0{
    data{
        nid => 1
        vid => 1
        type => article
        field_new{
            und{
                0{
                    value => 11111
                }
            }
        }
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        field_new{
            und{
                0{
                    value => 33333
                }
            }
        }
    }
}
...
0{
    data{
        nid => 1
        vid => 1
        type => article
        value => 11111
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        value => 33333
    }
}
<?php

$loop_count = count($input_arr);
for($i=0;$i<loop_count;$i++){
    //copy the value to the desired place
    $input_arr[$i]["data"]["value"] = $input_arr[$i]["data"]["field_new"]["und"][0]["value"];

    //delete the unwanted portion
    unset($input_arr[$i]["data"]["field_new"]);
} // for loops ENDS

?>
他是我们的朋友

unset()销毁指定的变量

使用此代码:

...
0{
    data{
        nid => 1
        vid => 1
        type => article
        field_new{
            und{
                0{
                    value => 11111
                }
            }
        }
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        field_new{
            und{
                0{
                    value => 33333
                }
            }
        }
    }
}
...
0{
    data{
        nid => 1
        vid => 1
        type => article
        value => 11111
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        value => 33333
    }
}
<?php

$loop_count = count($input_arr);
for($i=0;$i<loop_count;$i++){
    //copy the value to the desired place
    $input_arr[$i]["data"]["value"] = $input_arr[$i]["data"]["field_new"]["und"][0]["value"];

    //delete the unwanted portion
    unset($input_arr[$i]["data"]["field_new"]);
} // for loops ENDS

?>

假设:

...
0{
    data{
        nid => 1
        vid => 1
        type => article
        field_new{
            und{
                0{
                    value => 11111
                }
            }
        }
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        field_new{
            und{
                0{
                    value => 33333
                }
            }
        }
    }
}
...
0{
    data{
        nid => 1
        vid => 1
        type => article
        value => 11111
    }
}
1{
    data{
        nid => 2
        vid => 2
        type => article
        value => 33333
    }
}
<?php

$loop_count = count($input_arr);
for($i=0;$i<loop_count;$i++){
    //copy the value to the desired place
    $input_arr[$i]["data"]["value"] = $input_arr[$i]["data"]["field_new"]["und"][0]["value"];

    //delete the unwanted portion
    unset($input_arr[$i]["data"]["field_new"]);
} // for loops ENDS

?>
  • 您的基/父数组已建立数字索引
  • 在每个数组中,字段_new处于同一级别

请添加用于生成/获取此数组的代码,我们可以为您提供更具体的答案。

请尝试以文本形式而不是图像形式添加实际输出。也就是说,我所能看到的是,
field\u new(Arr…)
不在您的输出中。那么,你只是想删除它吗?field_new(Arr…)必须变成['value']=string(11111),谢谢
$Arr[$i][“data”][“value”]=$Arr[$i][“data”][“field_new”['und']['0'][“value”]工作,而不是
$input\u arr[$i][“data”][“value”]=$input\u arr[$i][“data”][“field\u new”][“value”]