0

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?

1
  • your current array structure prints like this Array ( [] => Array ( [date] => [text] => ) ) The index of the array is blank Commented Jan 31, 2015 at 7:01

1 Answer 1

2
<?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
    )

)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you raj for instant reply. goal achived :) but shows an error too " Undefined variable: each_complaints " on line no: 5 , but the line no: 5 is the array declaration
@ShifanaMubi : just declare $each_complaints = array(); before foreach loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.