Jump to content

Recommended Posts

Im trying to get a name from an array

 

Array
(
    [0] => Array
        (
            [name] => acid jazz
            [id] => 32
        )

    [1] => Array
        (
            [name] => african
            [id] => 78
        )

    [2] => Array
        (
            [name] => alternative country
            [id] => 62
        )

    [3] => Array
        (
            [name] => alternative dance
            [id] => 19
        )

    [4] => Array
        (
            [name] => alternative metal
            [id] => 33
        )

    [5] => Array
        (
            [name] => alternative rap
            [id] => 38
        )

)

 

Basically all ive got is the id, so if array[5] has id of 38 i want to return the name, aka "alternative rap"

 

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

Close but i only have the id "38" not the array number, is there a way i can number the array so i can just call the name?

 

Array
(
    [32] => Array
        (
            [name] => acid jazz
         )

    [78] => Array
        (
            [name] => african
        )

    [62] => Array
        (
            [name] => alternative country
        )

    [19] => Array
        (
            [name] => alternative dance
        )

    [4] => Array
        (
            [name] => alternative metal
            [id] => 33
        )

    [38] => Array
        (
            [name] => alternative rap
        )

)

Link to comment
https://forums.phpfreaks.com/topic/217917-array/#findComment-1130982
Share on other sites

In you want to be able to lookup/convert any number of values on a page, you would build a simple key/value array (see the code in this post - http://www.phpfreaks.com/forums/php-coding-help/using-$row-and-changing-values/msg1484306/#msg1484306)

 

If these are in a database and you are only getting one id/value on a page, you would do this in the query WHERE id = 38

Link to comment
https://forums.phpfreaks.com/topic/217917-array/#findComment-1130985
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.