Jump to content

sort($data);


Matt79

Recommended Posts

I have created a page that I place all of the acronyms that I come across.  I have them sorted in alphabetical order using the sort command. It sorts most of them correctly, but there are some that are in incorrect places. I have tried deleting the ones that are in the wrong place, but then new ones appear in their place. If anyone could give me some help that would be great. :-)

Below is the code that I created. I have all of the acronyms contained in the $raw_data variable.




$split=explode("1234567890",$raw_data);
sort($split);
$num=0;
$count=count($split);

while($num < $count)
{
echo $split[$num].'<br/>';
$num++;
}



Link to comment
Share on other sites

Ok you can see how it is being sorted here http://snyderit.info/test/acc.php

 

How I have the $raw_data setup is like this:

 

<?php
$raw_data="
customer premises equipment (CPE)1234567890
Service provider (SP)1234567890
virtual circuits (VC)1234567890
Point to Point Tunneling Protocol (PPTP)1234567890
Layer 2 Tunneling Protocol (L2TP)1234567890
IP security (IPsec)1234567890";


$split=explode("1234567890",$raw_data);
sort($split);
$num=0;
$count=count($split);

while($num < $count)
{
echo $split[$num].'<br/>';
$num++;
}
?>


 

Link to comment
Share on other sites

It is included in my previous posts. I tried strtoupper() and it did not change anything.

I want it to be in alphabetical order on the webpage. You can see how it is coming out here:

http://snyderit.info/test/acc.php Please note the DES near the bottom of the page.

 

The script I am using is here:

<?php
$raw_data="
customer premises equipment (CPE)&
Service provider (SP)&
virtual circuits (VC)&
Point to Point Tunneling Protocol (PPTP)&
Layer 2 Tunneling Protocol (L2TP)&
IP security (IPsec)&";


$split=explode("&",$raw_data);
sort($split);
$num=0;
$count=count($split);

while($num < $count)
{
echo $split[$num].'<br/>';
$num++;
}
?>

 

I did remove some of the acronyms before I posted it on the form since there are 188 of them. But the number should not matter.

 

Link to comment
Share on other sites

My 2cents

$raw_data="a customer premises equipment (CPE)
z Service provider (SP)
y virtual circuits (VC)
A Point to Point Tunneling Protocol (PPTP)
B Layer 2 Tunneling Protocol (L2TP)
6 IP security (IPsec)";

$split=explode("\n",$raw_data);
natcasesort($split);
foreach($split as $str){
echo "$str<br/>";
}

 

6 IP security (IPsec)

a customer premises equipment (CPE)

A Point to Point Tunneling Protocol (PPTP)

B Layer 2 Tunneling Protocol (L2TP)

y virtual circuits (VC)

z Service provider (SP)

Link to comment
Share on other sites

It almost appears random.

Almost random, except for the extraneous space characters attached to the 'malfunctioning' values. Get rid of that whitespace and I'd hazard a guess that the problem will go away. :shy:

 

[ot]Why are you splitting on 1234567890 rather than something more usual like... a line break?[/ot]

Link to comment
Share on other sites

Thanks MadTechie. I used the code you created and it worked, although I do not quite understand the differences. And I do not know why the a, z, y, A etc, are in your code. I am assuming it is to explain something but do not get it.

a customer premises equipment (CPE)
z Service provider (SP)
y virtual circuits (VC)
A Point to Point Tunneling Protocol (PPTP)
B Layer 2 Tunneling Protocol (L2TP)
6 IP security

 

 

My final script that works thanks to MadTechie:

 

 

<?php

$raw_data="
customer premises equipment (CPE)
Service provider (SP)
virtual circuits (VC)
Point to Point Tunneling Protocol (PPTP)
Layer 2 Tunneling Protocol (L2TP)
IP security (IPsec)
Provider Core (P)
";

$raw_data=strtoupper($raw_data);
$split=explode("\n",$raw_data);
natcasesort($split);
foreach($split as $str){



echo "$str<br/>";
}

?>

 

Thanks guys for all the help 8)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.