Jump to content

Php issue


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...