简体   繁体   中英

PHP Retrieve value from array

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
)

See array_keys() documentation

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

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.
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM