Jump to content

array()


dreamwest

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

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.