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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.