By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Sorting alphabetically backwards lists

P: n/a
This code runs @ http://www.ckoogle.com but the trouble is once I get
the list backwards, and in an array. I can't sort the new array into
alphabetical order. Anyone know a way to do it?

<?php

echo '<form action="index.php" method="post">';
echo '<textarea name="input" cols="12" rows="20">';
echo '</textarea><br>';
echo '<input type="submit" value="Submit">';
echo '</form>';

if( isset( $_POST["input"] )){
$my_array = $_POST["input"];
$my_array=strrev($my_array);
$my_array=explode("\n", $my_array);
print_r($my_array);
sort($my_array);
print_r($my_array);
for($cnt=0; $cnt < count($my_array); $cnt++)
{
echo(strrev($my_array[$cnt]));
echo('<br>');
}
}
?>

Feb 18 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
CoreyWhite wrote:
This code runs @ http://www.ckoogle.com but the trouble is once I get
the list backwards, and in an array. I can't sort the new array into
alphabetical order. Anyone know a way to do it?
Sort the array, then transverse it using the foreach construct.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"Do, or do not. There is no 'try'."
- Yoda ('The Empire Strikes Back')
Feb 18 '07 #2

P: n/a
On Feb 17, 10:04 pm, Ivn Snchez Ortega <ivansanche...@rroba--
escomposlinux.punto.netwrote:
CoreyWhite wrote:
This code runs @http://www.ckoogle.com but the trouble is once I get
the list backwards, and in an array. I can't sort the new array into
alphabetical order. Anyone know a way to do it?

Sort the array, then transverse it using the foreach construct.

--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"Do, or do not. There is no 'try'."
- Yoda ('The Empire Strikes Back')

Could you post the code changes I need please?

Feb 18 '07 #3

P: n/a
"CoreyWhite" <Co********@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
This code runs @ http://www.ckoogle.com but the trouble is once I get
the list backwards, and in an array. I can't sort the new array into
alphabetical order. Anyone know a way to do it?
Could you explain this with a bit more details. Now this sounds to me like
you either shouldn't reverse it in the first place if you indeed want it
sorted alphabetically or if you want it reversed, then I can't see the
problem, it is in backwards alphabetical order. And furthermore, I don't see
the "new" array anywhere, you opereate only one array, $my_array.
<?php

echo '<form action="index.php" method="post">';
echo '<textarea name="input" cols="12" rows="20">';
echo '</textarea><br>';
echo '<input type="submit" value="Submit">';
echo '</form>';

if( isset( $_POST["input"] )){
$my_array = $_POST["input"];
$my_array=strrev($my_array);
$my_array=explode("\n", $my_array);
print_r($my_array);
sort($my_array);
print_r($my_array);
for($cnt=0; $cnt < count($my_array); $cnt++)
{
echo(strrev($my_array[$cnt]));
echo('<br>');
}
}
?>

Feb 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.