我有以下代码从数组中删除一个元素:
for ($i = 0; $i < count($contracte); $i++) {
if ($contracte[$i]['total_luni_contract'] == $contracte[$i]['luni_contract_cu_cheltuieli']) {
unset($contracte[$i]);
}
}
数组如下所示:
Array
(
[0] => Array
(
[id_contract] => 3
[numar] => 2955
[data] => 2011-04-04
[total_luni_contract] => 2
[luni_contract_cu_cheltuieli] => 0
)
[1] => Array
(
[id_contract] => 25
[numar] => 14
[data] => 2013-01-07
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 1
)
[2] => Array
(
[id_contract] => 26
[numar] => 15
[data] => 2013-01-07
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 1
)
[3] => Array
(
[id_contract] => 27
[numar] => 16
[data] => 2013-01-07
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[4] => Array
(
[id_contract] => 28
[numar] => 17
[data] => 2013-01-07
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[5] => Array
(
[id_contract] => 29
[numar] => 23
[data] => 2013-01-08
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 0
)
[6] => Array
(
[id_contract] => 30
[numar] => 24
[data] => 2013-01-08
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 0
)
[7] => Array
(
[id_contract] => 31
[numar] => 33
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 1
)
[8] => Array
(
[id_contract] => 32
[numar] => 34
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[9] => Array
(
[id_contract] => 33
[numar] => 35
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[10] => Array
(
[id_contract] => 34
[numar] => 36
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[11] => Array
(
[id_contract] => 35
[numar] => 37
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[12] => Array
(
[id_contract] => 36
[numar] => 38
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[13] => Array
(
[id_contract] => 37
[numar] => 39
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[14] => Array
(
[id_contract] => 38
[numar] => 40
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[15] => Array
(
[id_contract] => 39
[numar] => 41
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[16] => Array
(
[id_contract] => 40
[numar] => 42
[data] => 2013-01-09
[total_luni_contract] => 1
[luni_contract_cu_cheltuieli] => 0
)
[17] => Array
(
[id_contract] => 41
[numar] => 43
[data] => 2013-01-09
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 0
)
[18] => Array
(
[id_contract] => 42
[numar] => 44
[data] => 2013-01-09
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 0
)
[19] => Array
(
[id_contract] => 43
[numar] => 45
[data] => 2013-01-09
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 0
)
[20] => Array
(
[id_contract] => 44
[numar] => 46
[data] => 2013-01-09
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 6
)
[21] => Array
(
[id_contract] => 45
[numar] => 47
[data] => 2013-01-09
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 6
)
[22] => Array
(
[id_contract] => 46
[numar] => 48
[data] => 2013-01-09
[total_luni_contract] => 6
[luni_contract_cu_cheltuieli] => 4
)
)
运行代码后,数组保持不变。它应该取消设置$contracte[1]
,$contracte[2]
和。$contracte[7]
$contracte[20]
有什么想法吗?