Q:

Write a PHP function to sort entity letters

0

Write a PHP function to sort entity letters

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function entity_sort($my_array) {
    $total = count($my_array);
    for ($i=0;$i<$total;$i++) {
        if ($my_array[$i]{0} == '&') {
            $my_array[$i] = $my_array[$i]{1}.$my_array[$i];
        } else {
            $my_array[$i] = $my_array[$i]{0}.$my_array[$i];
        }
    }
    sort($my_array);
        for ($i=0;$i<$total;$i++) {
        $my_array[$i] = substr($my_array[$i],1);
    }
        return $my_array;
    }
$arr = array(" ","&", "<");
print_r(entity_sort($arr));
?>

Sample Output:

Array                                                       
(                                                           
    [0] =>                                                  
    [1] => <                                                
    [2] =>                                                  
)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now