php array reorder values in key

200

sometimes I have in array list as 4,5,1,2 and sometimes 1,2,4,5. How could I reorder values in [list] ASC so I will have 1,2,4,5 and 1,2,3 etc in all [list] fields? Thank you.

Array
(
    [0] => DibiRow Object
        (
            [storage:ArrayObject:private] => Array
                (
                    [d] => 2012-04-03 08:30:00
                    [list] => 4,5,1,2
                )

        )

    [1] => DibiRow Object
        (
            [storage:ArrayObject:private] => Array
                (
                    [d] => 2012-04-03 09:00:00
                    [list] => 1,2,4,5
                )

        )

    [2] => DibiRow Object
        (
            [storage:ArrayObject:private] => Array
                (
                    [d] => 2012-04-03 09:00:00
                    [list] => 3,1,2                    )

        )
    [3] => DibiRow Object
        (
            [storage:ArrayObject:private] => Array
                (
                    [d] => 2012-04-03 09:00:00
                    [list] => 1,2,3                    )

        )
269

Answer

Solution:

Try reading something about bubble sorting first. Then google it, find some examples and try to do it yourself. If you still have problems, come back and ask again, specifying what have you tried and what you think it's wrong with your method.

244

Answer

Solution:

thank you. I found this solution (don't know if it is effective with large data):

for ($i = 0; $i < count($all) ; $i++) {
  $num = $all[$i][list];
  $resort = explode(",", $num);
  sort($resort);
  $resort = implode(",", $resort); 
  $all[$i][list] = $resort;
}
432

Answer

Solution:

If this is based on the GROUP_CONCAT in results of previous query I wrote you can simply add ORDER BY to the GROUP_CONCAT() -

GROUP_CONCAT(DISTINCT user_bookings.user_id ORDER BY user_bookings.user_id)

People are also looking for solutions to the problem: php - cloudfiles API: uncaught exception with get_container when container doesn't exist

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.