按键删除外部数组
remove outer array by key
我的数组如下图
Array
(
[0] => Array
(
[cwgetOptionsResponse] => Array
(
[cwdetails] => Array
(
[cwNameDetail] => Array
(
[cwName] => Array
(
[cwNameId] => 1
)
[cwPostCode] => PDP/E225
[cwPrints] => Array
(
[cwSurname] => 1088138401
[cwColourStatus] => passed
)
)
)
)
)
)
我希望删除 cwgetOptionsResponse、cwdetails 和 cwNameDetail 以获得如下所示的数组。我试过 array_shift 但这会删除外部元素。有什么方法可以通过按键删除数组吗?
Array
(
[0] => Array
(
[cwName] => Array
(
[cwNameId] => 1
)
[cwPostCode] => PDP/E225
[cwPrints] => Array
(
[cwSurname] => 1088138401
[cwColourStatus] => passed
)
)
)
解决方案 1:
您可以使用array_shift()
示例:
$oldarray = array(array('cwgetOptionsResponse' => array("cwdetails" => array("cwNameDetail" => array("cwName" => array("cwNameId" => 1))))));
print_r(($a));
$removezero = array_shift($oldarray );
$removecwgetOptionsResponse = array_shift($oldarray);
$removecwdetails = array_shift($oldarray);
$cwNameDetail = array_shift($oldarray);
$cwNameDetail 将包含您想要的数组,或者如果需要,您可以将其组合成单个变量。
解决方案 2:
在新数组中插入值:
$newarray = $oldarray[0]['cwgetOptionsResponse']['cwdetails']['cwNameDetail'];
我的数组如下图
Array
(
[0] => Array
(
[cwgetOptionsResponse] => Array
(
[cwdetails] => Array
(
[cwNameDetail] => Array
(
[cwName] => Array
(
[cwNameId] => 1
)
[cwPostCode] => PDP/E225
[cwPrints] => Array
(
[cwSurname] => 1088138401
[cwColourStatus] => passed
)
)
)
)
)
)
我希望删除 cwgetOptionsResponse、cwdetails 和 cwNameDetail 以获得如下所示的数组。我试过 array_shift 但这会删除外部元素。有什么方法可以通过按键删除数组吗?
Array
(
[0] => Array
(
[cwName] => Array
(
[cwNameId] => 1
)
[cwPostCode] => PDP/E225
[cwPrints] => Array
(
[cwSurname] => 1088138401
[cwColourStatus] => passed
)
)
)
解决方案 1:
您可以使用array_shift()
示例:
$oldarray = array(array('cwgetOptionsResponse' => array("cwdetails" => array("cwNameDetail" => array("cwName" => array("cwNameId" => 1))))));
print_r(($a));
$removezero = array_shift($oldarray );
$removecwgetOptionsResponse = array_shift($oldarray);
$removecwdetails = array_shift($oldarray);
$cwNameDetail = array_shift($oldarray);
$cwNameDetail 将包含您想要的数组,或者如果需要,您可以将其组合成单个变量。
解决方案 2:
在新数组中插入值:
$newarray = $oldarray[0]['cwgetOptionsResponse']['cwdetails']['cwNameDetail'];