Solved

is it possible to use HashMap in php?

Posted on 2007-04-05
2
4,337 Views
Last Modified: 2010-01-14
I have done
$path = "./";
$r= opendir($path);
$numfiles=0;
while ($fichier = readdir($r)){
 if (strpos($fichier,".")>0) {
            $dossier$numfiles]=substr($fichier,strpos($fichier,".")+1);
            $filename[$numfiles]=substr($fichier,0,strpos($fichier,"."));
            $numfiles++;
            }
 }
// Sort the array
sort($filename);
 closedir($r);
but I would like to sort also $dossier because $filename[$numfiles] must correspond to $dossier$numfiles]. HNow can I do? Is it possible to use hasmap in php?

Thanks

Regards
0
Comment
Question by:pofpof98
  • 2
2 Comments
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 500 total points
ID: 18886807
The answer is not really.

However this may do what you want.

<?PHP
$path = "./";
$r= opendir($path);
$numfiles=0;
while ($fichier = readdir($r)){
      if (strpos($fichier,".")>0) {
            $filename[$numfiles] = substr($fichier,0,strpos($fichier,"."));
            $dossier[$numfiles] = substr($fichier,strpos($fichier,".")+1);
            $numfiles += 1;
      }
}
closedir($r);

$map = array_combine($filename, $dossier);

// Sort the array
asort($map);

foreach($map as $filename => $dossier) {
      echo $filename . " " . $dossier . "<br>";
}

?>
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18933540
Thanks pofpof98!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to count occurrences of each item in an array.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now