sabeti05 Posted July 28, 2015 Share Posted July 28, 2015 Hi, I'm new here and in php, I wrote this: <?php $var = array('<a href="3">a</a>', '<a href="1">b</a>', '<a href="2">c</a>'); sort($var); foreach($var as $value){ echo $value, '<br>'; } ?> the output is: bca how can I change its output to: a b c thank you all! Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted July 28, 2015 Solution Share Posted July 28, 2015 use a custom sort function with usort() $var = array('<a href="3">a</a>', '<a href="1">b</a>', '<a href="2">c</a>'); usort($var, 'mysort'); foreach($var as $value){ echo $value, '<br>'; } function mysort($a, $b) { return strcmp(strip_tags($a),strip_tags($b)); } Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted July 28, 2015 Share Posted July 28, 2015 You should make a habit to separate coding logic from html. Only add html for display, not stored in arrays. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.