Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers

up vote 3 down vote accepted

if i understood you, try this:

$statement[count($statement)-1]['flex'] = 1;
share|improve this answer
<?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
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.