Jump to content

Php issue


sugan

Recommended Posts

hi,I have an array like

$aa = array('Aman', 'Amir', 'Banu', 'Bob', 'Celina', 'Danny')

Now i want an output as:

A B C DAAman Amir
Here B, C, D should be links, so that when i click B it should list B names alone..How to work for it! Pls Help!Regards,Suganya
Link to comment
Share on other sites

  <?php  $aa = array('Aman', 'Amir', 'Banu', 'Bob', 'Celina', 'Danny');    $firstLetters = array();  foreach ($aa as $value) #get the first letters   {      if(!in_array($value[0], $firstLetters))      {          $firstLetters[] = $value[0];      }  }    $firstLetter = "A";  if(isset($_GET['letter']))      $firstLetter = $_GET['letter'];          #print links  foreach ($firstLetters as $value)  {      if(strtolower($value)!= strtolower($firstLetter))      {          echo "<a href='?letter={$value}'>{$value}</a>  ";      }      else      {          echo $value."  ";      }  }    echo "<br><br>";  #print array elements matching selected letter    foreach($aa as $value)  {      if(strtolower($value[0]) == strtolower($firstLetter))      {          echo $value." ";      }  }    ?>  

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...