0

I'm trying to use sort function for an array after array_unique function but I'm getting below error:

A PHP Error was encountered
Severity: Warning
Message: implode() [function.implode]: Invalid arguments passed
Filename: controllers/admin.php
Line Number: 250

Below is my loop function. How can I sort by value ascending?

foreach ($bars as $bar){

                $explode = explode(',',$bar->date_id);
                $i = 0;
                $b = array();
                foreach($explode as $bars){
                        $bars = intval($bars);
                        @$b[$i] .= $bars;
                        $i++;
                }

                $date_id = array_unique($b);
                $date_id = sort($date_id);

                echo "<pre>";
                print_r($date_id);
                echo "</pre>";
                $date_id = implode(',',$date_id);
                echo "<pre>";
                print_r($date_id);
                echo "</pre>";
}

1 Answer 1

3

Among other things that look awry with your code, sort() returns TRUE or FALSE, not the sorted array.

Instead of this:

$date_id = array_unique($b);
$date_id = sort($date_id);

Use this:

$date_id = array_unique($b);
sort($date_id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.