0

How do I retrieve the date values from the following array? Actually, want I want to do is loop through this array, and create a table cell for each of the date values. Thanks,

Array
(
    [2011-11-18 00:00:00] => 3
    [2011-11-22 00:00:00] => 2
)
1
  • That is not a multidimensional array. Commented Nov 27, 2011 at 20:45

3 Answers 3

2

Use this code to iterate over the array :

foreach($yourarray as $key => $value){
    echo '<tr>';
    echo '<td>'.$key.'</td>'; //will print "2011-11-18 00:00:00"
    echo '<td>'.$value.'</td>'; //will print "3"
    echo '</tr>';
}

You should read about the foreach construct and the Array data type.

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

Comments

2

See array_keys() documentation

http://php.net/manual/en/function.array-keys.php

1 Comment

+1 Although you weren't acknowledged, this seems to be exactly what the OP asked for.
2

If you want to loop, try:

// assuming variable is named $array
foreach($array as $k => $v) {
    echo "Key: ".$k.", Value: ".$v."<br />\n";
    // or whatever it is you want with them.
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.