is it possible to use HashMap in php?

Posted on 2007-04-05
Last Modified: 2010-01-14
I have done
$path = "./";
$r= opendir($path);
while ($fichier = readdir($r)){
 if (strpos($fichier,".")>0) {
// Sort the array
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?


Question by:pofpof98
  • 2
LVL 29

Accepted Solution

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

However this may do what you want.

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

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

// Sort the array

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

LVL 29

Expert Comment

ID: 18933540
Thanks pofpof98!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 39
test if query has no results 2 19
datetime in sql 6 28
Configure a Bean in an XML file 4 9
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

920 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

14 Experts available now in Live!

Get 1:1 Help Now