Jump to content

php array sorting


Destramic

Recommended Posts

i have an array from a database that looks like this (below) but what i want is for the array to be sorted assedningly by the start position

 

so the team with start position 1 will be 1st and so on...if anyone can help me on what i should do please...thank you

 

Array
(
    [1] => Array
        (
            [team_name] => A Team
            [team_nationality] => British
            [start_position] => 2
        )

    [2] => Array
        (
            [team_name] => B Team
            [team_nationality] => British
            [start_position] => 1
        )
    [3] => Array
        (
            [team_name] => C Team
            [team_nationality] => British
            [start_position] => 4
        )

    [4] => Array
        (
            [team_name] => B Team
            [team_nationality] => British
            [start_position] => 3
        )

)

Link to comment
https://forums.phpfreaks.com/topic/248625-php-array-sorting/
Share on other sites

thanks guys...one last thing...how can i convert a php array to a javascript array please?

 

Create a foreach loop to "write out" the array values into the page in the format you want for the JavaScript array. YOU have to decide how you want the JavaScript array to be structured. JS arrays do not allowed named keys. You can use named keys - but then it is an "object" in JS and not an array - which changes how you can use it.

Link to comment
https://forums.phpfreaks.com/topic/248625-php-array-sorting/#findComment-1276904
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.