我有一个多维数组,如下所示
Array
(
[0] => attributewidget Object
(
[_child] => Array
(
)
[_parent] =>
[_oid] => a_1
[_errorMsg] =>
[_debugTraceFunc] =>
[classname] => AttributeWidget
[version] => 1.0.0.0
[attributeName] =>
[comparableProperties] => Array
(
[0] => abbreviation
[1] => attributeName
[2] => classname
[3] => conditionRef
)
)
[1] => Array
(
[0] => attributewidget Object
(
[_child] => Array
(
)
[_parent] =>
[_oid] => a_2
[_errorMsg] =>
[_debugTraceFunc] =>
[classname] => AttributeWidget
[version] => 1.0.0.0
[attributeName] =>
[comparableProperties] => Array
(
[0] => abbreviation
[1] => attributeName
[2] => classname
[3] => conditionRef
)
)
)
[2] => Array
(
[0] => attributewidget Object
(
[_child] => Array
(
)
[_parent] =>
[_oid] => a_3
[_errorMsg] =>
[_debugTraceFunc] =>
[classname] => AttributeWidget
[version] => 1.0.0.0
[attributeName] => cp1
[comparableProperties] => Array
(
[0] => abbreviation
[1] => attributeName
[2] => classname
[3] => conditionRef
)
)
)
)
我理想地想删除[1] =>数组[2] =>数组并重新排列索引。 有没有办法让索引重新排列如下。
Array
(
[0] => attributewidget Object
(
[_child] => Array
(
)
[_parent] =>
[_oid] => a_1
[_errorMsg] =>
[_debugTraceFunc] =>
[classname] => AttributeWidget
[version] => 1.0.0.0
[attributeName] =>
[comparableProperties] => Array
(
[0] => abbreviation
[1] => attributeName
[2] => classname
[3] => conditionRef
)
)
[1] => attributewidget Object
(
[_child] => Array
(
)
[_parent] =>
[_oid] => a_2
[_errorMsg] =>
[_debugTraceFunc] =>
[classname] => AttributeWidget
[version] => 1.0.0.0
[attributeName] => Name?
[comparableProperties] => Array
(
[0] => abbreviation
[1] => attributeName
[2] => classname
[3] => conditionRef
)
)
[2] => attributewidget Object
(
[_child] => Array
(
)
[_parent] =>
[_oid] => a_3
[_errorMsg] =>
[_debugTraceFunc] =>
[classname] => AttributeWidget
[version] => 1.0.0.0
[attributeName] => cp1
[comparableProperties] => Array
(
[0] => abbreviation
[1] => attributeName
[2] => classname
[3] => conditionRef
)
)
)
答案 0 :(得分:2)
循环遍历数组,并将嵌套数组的任何元素替换为其第一个元素,以删除该额外级别的间接。
foreach ($array as &$element) {
if (is_array($element) {
$element = $element[0];
}
}