Solved

is it possible to use HashMap in php?

Posted on 2007-04-05
2
4,397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

734 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