phparraysmultidimensional-array

array_push() on multidimensional arrays and display its elements


My current project consist of multidimensional arrays in which it holds a date and some text contents.

I already used the normal arrays in my project and array_push() is used for inserting an element to array. Now I'm stuck with a multidimensional array in which I don't know how to insert and display multidimensional array data.

I created a multidimensional array like this:

$complaints = array(
    $each_complaints => array(
        "date" => "",
        "text" => ""
    )
);

then I want to add data's into this array on the loop of mysql result

<?php foreach($query_56 as $notes):
          // eg: array_push " $notes->date , $notes->corresponding_text "
endforeach; ?>

I want to display the array like this:

array[date][text]=> [2014-11-18] [1st complaint]
array[date][text]=> [2015-01-15] [2nd complaint]

How can I achieve this?


Solution

  • <?php foreach($query_56 as $key=>$notes):
           $each_complaints[$key]["date"] = $notes->date;
           $each_complaints[$key]["text"] = $notes->corresponding_text ;           
    endforeach;
    
    echo "<pre>";print_r($each_complaints);
    ?>
    **Output :** 
    (
    [0] => Array
        (
            [date] => 01-11-2014
            [text] => rrrrrr
        )
    
    [1] => Array
        (
            [date] => 02-11-2014
            [text] => fffff
        )
    
    [2] => Array
        (
            [date] => 03-11-2014
            [text] => ddddd
        )
    
    )