编辑最后一个多维数组项

时间:2018-08-02 02:09:48

标签: php

我需要编辑多维数组中的最后一项

Array
(
   [0] => Array
    (
        [column] => Country
        [operator] => =
        [value] => 2
        [total] => 0
    )

   [1] => Array
    (
        [column] => State
        [operator] => =
        [value] => 1
        [total] => 0
    )

)

仅编辑最后一个数组的total字段

$count = count( $array);
$ultimaChave[$count]['total'] = 55; 

1 个答案:

答案 0 :(得分:2)

PHP使用基于零的索引,因此您只需要获取数组长度减去一即可:

$count = count($array);
$array[$count-1]['total'] = 55;