3

我有

$statement = Array
(
    [0] => Array
        (
            [red] => 06-01-2012
            [green] => 436
            [blue] => MEDIA
            [black] => 2006
        )

    [1] => Array
        (
            [red] => 06-01-2012
            [green] => 430
            [blue] => MEDIA
            [black] => 2007
        )

);

我想[flex] => 1通过使用类似 $statement[1] 的东西添加到数组 1 中。我尝试过数组合并,但他们将数组 0 和 1 组合在一起。基本上我想添加到最新的。

4

2 回答 2

7

如果我理解你,试试这个:

$statement[count($statement)-1]['flex'] = 1;
于 2012-06-15T06:37:30.157 回答
5
<?php
$statement = array(
    array(
            "red" => 06-01-2012,
            "green" => 436,
            "blue" => "MEDIA",
            "black" => 2006
        )

    ,array(
            "red" => 06-01-2012,
            "green" => 436,
            "blue" => "MEDIA",
            "black" => 2006
        )

);

echo "<pre>";
print_r($statement); //first

$statement[1]["flex"] = 1;

print_r($statement); //second
?>
于 2012-06-15T06:42:43.887 回答