0

I am trying to pull in this date for each part of my database, but I am missing some element to make it work and not sure what I am missing?

 $modified[] = array(date("m/d/y", strtotime($row[audit_modify_date]))."<br />".date("g:i a", strtotime($row[audit_modify_date])),);

//query
 for ($i=0; $i < count($result); $i++) {
        echo "<tr>";
            echo "<td>$modified</td>";
        echo"<tr>";
 }      

They output just says Array.

3
  • 1
    why are you using an array anyways? that looks like you're generating a single string anyways, which can go into $modified directly, not need to be turned into a single element array. Commented Jun 9, 2016 at 21:06
  • It gets pulled many times for multiple rows, But what would be a better way then? Commented Jun 9, 2016 at 21:23
  • doesn't matter. why have a double array in the first place? for(...) { $modified = date(...strtotime(...)); echo " blah blah $modified "; } no need for an array at all. Commented Jun 9, 2016 at 21:44

2 Answers 2

1

You are printing the array, not the elements in the array

echo "<td>$modified</td>";

either

for ($i=0; $i < count($result); $i++) {
    echo "<tr>";
    echo "<td>".$modified[$i]."</td>";
    echo"<tr>";
} 

or

foreach ($modified as $m) {
    echo $m;
}

edit actually what? I don't understand what you're doing

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

4 Comments

It still says array, and I know you are right. Must be some other little thing
are you sure you don't mean $modified = ... instead of $modified[] = ...?
@SDJ it's because you are putting another array inside your $modified array.
I was because of the 1st modified[], should have been without the [] brackets
1

Since you are using $modified[ ] = array(....), it becomes multidimensional array. Use below code

for ($i=0; $i < count($result); $i++) {
    echo "<tr>";
        echo "<td>$modified[0][$i]</td>";
    echo"<tr>";
} 

Or just

echo "<td>$modified[0][0]</td>";

Other thing is instead of creating a array, make it a variable like shown below

$modified=date("m/d/y", strtotime($row[audit_modify_date]))."<br />".date("g:i a", strtotime($row[audit_modify_date]));

//query
   for ($i=0; $i < count($result); $i++) {
    echo "<tr>";
        echo "<td>$modified</td>";
    echo"<tr>";
 }   

Note: use the appropriate according to your requirement.

1 Comment

Great idea! This code keeps looking better. Thanks!

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.