3D 协会。数组如下所示。
Array
(
[COL] => Array
(
[0] => Array
(
[emp_num] => 1000001
[user_name] => Test User
[amount] => 775.00
[name] => COL
)
[1] => Array
(
[emp_num] => 26
[user_name] => John Doe
[amount] => 555.00
[name] => COL
)
)
[RA. 20%] => Array
(
[0] => Array
(
[emp_num] => 1000001
[user_name] => Test User
[amount] => 110.00
[name] => RA. 20%
)
)
[BS] => Array
(
[0] => Array
(
[emp_num] => 1000001
[user_name] => Test User
[amount] => 444.00
[name] => BS
)
)
)
我想删除key=>value
每个最内层数组的最后一对。(想要删除键具有 [name] 的键值对)结果应该类似于下面的数组。
Array
(
[COL] => Array
(
[0] => Array
(
[emp_num] => 1000001
[user_name] => Test User
[amount] => 775.00
)
[1] => Array
(
[emp_num] => 26
[user_name] => John Doe
[amount] => 555.00
)
)
[RA. 20%] => Array
(
[0] => Array
(
[emp_num] => 1000001
[user_name] => Test User
[amount] => 110.00
)
)
[BS] => Array
(
[0] => Array
(
[emp_num] => 1000001
[user_name] => Test User
[amount] => 444.00
)
)
)
我写了一个函数来做到这一点。
<!-- language: php -->
function remove_name_from_psa($psa_array){
foreach( $psa_array as $key=>$value ) {
foreach( $value as $key2=>$value2 ){
foreach( $value2 as $key3=>$value3 ){
if( $key3 != 'name') {
$psa_name_removed[$key][$value[$key2][$value2[$key3]]] = $value3;
}
}
}
}
return $psa_name_removed;
}
返回的数组就是这个,这显然不是我需要的。
Array ( [COST OF LIVING] => Array
( [] => 555.00 )
[RENT ALLOW. 20%] => Array
( [] => 110.00 )
[BASIC SALARY] => Array
( [] => 444.00 )
)
并且有很多未定义的偏移量和未定义的索引通知。
$psa_name_removed[$key][$value[$key2][$value2[$key3]]] = $value3;
//这是我做错的那一行吗?还是整个方法都是错误的?:-P
我怎样才能让它工作?任何人都可以帮忙吗?
谢谢你!