Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

is it possible to use HashMap in php?

Posted on 2007-04-05
2
Medium Priority
?
4,409 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

721 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