Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

Adding Key and Value to PHP Associative Array

Experts,
I am having some trouble with my code.  I have the following:
foreach( $files as $fname )
{
	$filedate = date("m/d/Y", filemtime($fname));
	$file_name = substr($fname,0,7).' Entry Report - '.$filedate;
	$final[$fname] = $file_name;
	
}

sort($final);
print_r($final);

Open in new window


I am wanting to add key and value to the $final array.  The value goes in fine, but the output of the print_r displays numerical keys instead of the value I assigned. Both $fname and $file_name have the correct values assigned. What am I doing wrong?

Thanks..
0
kwilliams123
Asked:
kwilliams123
1 Solution
 
Lukasz ChmielewskiCommented:
use asort($final)
instead of sort, it reassigns the keys
0
 
kwilliams123Author Commented:
That did it..  Thanks for your prompt response.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now