我在codeigniter工作。我有一个像父母一样的数组,它的子项显示在下面。
Array
(
[id] => 27
[Name] => MUKESH CHUNAWALA
[children] => Array
(
[0] => Array
(
[id] => 160
[Name] => PRAVINBHAI PARMAR
[children] => Array
(
[0] => Array
(
[id] => 161
[Name] => ARATIBEN PRAVINBHAI PARMAR
[amnt] => 0
)
)
[amnt] => 0
)
[1] => Array
(
[id] => 188
[Name] => pravinbhai parmar
[amnt] => 0
)
[2] => Array
(
[id] => 189
[Name] => AMRISHBHAI S. CHUNAWALA
[amnt] => 0
)
[3] => Array
(
[id] => 190
[Name] => DHARMESH RANA
[amnt] => 0
)
[4] => Array
(
[id] => 191
[Name] => Chadhri Kavita
[amnt] => 0
)
[5] => Array
(
[id] => 192
[Name] => vasava Shitalben
[amnt] => 0
)
[6] => Array
(
[id] => 194
[Name] => SUDHABEN R CHUNAWALA
[amnt] => 0
)
[7] => Array
(
[id] => 195
[Name] => SAROJBEN R PARMAR
[amnt] => 0
)
[8] => Array
(
[id] => 196
[Name] => Rabari.Shantilal.B
[amnt] => 0
)
[9] => Array
(
[id] => 197
[Name] => POOJABHAI.A.BARIYA
[amnt] => 0
)
[10] => Array
(
[id] => 198
[Name] => LATABEN VASAVA
[amnt] => 0
)
[11] => Array
(
[id] => 199
[Name] => ARVINDBHAI VASAVA
[amnt] => 0
)
[12] => Array
(
[id] => 200
[Name] => ROHIT VARSHABEN LALITBHAI
[amnt] => 0
)
[13] => Array
(
[id] => 201
[Name] => CHHATRIVALA HINABEN HARISHBHAI
[amnt] => 40
)
[14] => Array
(
[id] => 202
[Name] => MANISHABEN CHUNAWALA
[amnt] => 40
)
[15] => Array
(
[id] => 203
[Name] => KALPANA J RANA
[amnt] => 40
)
[16] => Array
(
[id] => 204
[Name] => CHUNAWALA SHAILESHKUMAR G
[amnt] => 40
)
[17] => Array
(
[id] => 205
[Name] => Anitaben.b Rajput
[amnt] => 184
)
[18] => Array
(
[id] => 206
[Name] => VASANTBHAI VASAVA
[amnt] => 184
)
[19] => Array
(
[id] => 207
[Name] => vasant.f.vasava
[amnt] => 328
)
[20] => Array
(
[id] => 208
[Name] => SALAT SADIKHUSEN GULAMMAHAMMAD
[amnt] => 376
)
[21] => Array
(
[id] => 211
[Name] => Ranjit B Vasava
[amnt] => 376
)
[22] => Array
(
[id] => 212
[Name] => JIVANBHAI P VAGHELA
[amnt] => 376
)
[23] => Array
(
[id] => 214
[Name] => RAMESHBHAI BARIYA
[amnt] => 376
)
[24] => Array
(
[id] => 215
[Name] => MANSURI SALEEMBHAI RASULBHAI
[amnt] => 376
)
[25] => Array
(
[id] => 218
[Name] => MANSURI SALEEMBHAI RASULBHAI
[children] => Array
(
[0] => Array
(
[id] => 161
[Name] => ARATIBEN PRAVINBHAI PARMAR
[amnt] => 616
)
)
[amnt] => 616
)
[26] => Array
(
[id] => 219
[Name] => BHARATBHAI VANKAR
[amnt] => 616
)
[27] => Array
(
[id] => 221
[Name] => MUSTUFAKHAN K PATHAN
[amnt] => 616
)
)
)
现在,我想获取最后一个id的数量。这里,最后一个id是27.所以我想要获取27个id的数量。那么我应该编写什么代码才能获得最后一个ID?
我想从父数组中获取Name,那么我应该编写什么代码?
答案 0 :(得分:7)
$last = end($your_array['children']);
$amt = $last['amnt'];
请注意end()
使数组的内部指针前进到最后一个元素。