3

I have

$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
        )

);

And I want to add [flex] => 1 into array 1 by using something like $statement[1]. I have tried with array merge but they have combined array 0 and 1. Basically I want to add to the latest one.

ilhan
  • 8,700
  • 35
  • 117
  • 201

2 Answers2

7

if i understood you, try this:

$statement[count($statement)-1]['flex'] = 1;
k102
  • 7,861
  • 7
  • 49
  • 69
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
?>
Karandeep Singh
  • 1,223
  • 5
  • 22
  • 34