Re: Subject: Creating an Associative Array
| From: | Neil Smith [MVP, Digital media] | Date: | Wed, 08 Jun 2005 22:19:04 +0000 |
| Subject: | Re: Subject: Creating an Associative Array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39620@lists.php.net to get a copy of this message | ||
At 21:04 08/06/2005 +0000, you wrote:
To: <php-db@lists.php.net> MIME-Version: 1.0 Message-ID: <OFF3E84E33.DE4EB8F9-ON8625701A.006FDDB7-8625701A.0073C616@mdacc.tmc.edu> From: dpgirago@mdanderson.org Date: Wed, 8 Jun 2005 16:04:33 -0500 Content-Type: multipart/alternative; boundary="=_alternative 0073C60C8625701A_=" Subject: Creating an Associative Array This question will probably be off-topic for some, but it does relate to a database application so please bear with me. I'm pulling date-times out of a MySQL db: mysql> select date_format(Actually you meant to pass the $dateArray an index - as you didn't, PHP helpfully created sequential numeric indices. Try this instead, providing the date index string yourself : $dateArray[ date("Y.m.d H:i:s", $now - $counter) ] = array( (int)ceil(980 - ($counter * .2333333333333))); Cheers - Neildate_time, '%Y.%m.%d %H:%i:%s') as rightNow from location1 order by date_time desc limit 1; +----------------------------+| rightNow |+----------------------------+ | 2005.06.08 14:24:11 | +----------------------------+ This code snippet is producing an array of arrays rather than a simple associative array: <?php $now = time(); //$dateArray = array(); (output is the same with or without this line) for($counter = 0; $counter <= 3600; $counter++) {$dateArray[] = array(date("Y.m.d H:i:s", $now - $counter) =>(int)ceil(980 - ($counter * .2333333333333))); }