phparraysmultidimensional-arraydeclaration

How to add a new row to a pre-existing 2d array?


Please help me to create multidimensional array. I'm using ajax. When a new request comes, then new array needs to be appended to the pre-existing array.

$_session['calculate'] = array(
    "filename" => $filename,
    "source" => $source,
    "destination" => $destination,
    "subjectarea" => $subjectarea,
    "total_word" => $total_word,
    "total_price" => $total_price,
    "euro" => 20,
    "chf" => 30,
);

Solution

  • Just try with:

    $_session['calculations'][] = array(
        "filename" => $filename,
        ...
    );
    

    and then again..

    $_session['calculations'][] = array(
        "filename" => $filename,
        ...
    );
    

    You will get a calculations array of arrays with your data :)