explain about arrays please.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

explain about arrays please.

Post by spamyboy »

If I get my result array:

Code: Select all

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => pirma kategorija
        )

    [1] => Array
        (
            [id] => 2
            [name] => antra kategorija
        )

)
and I need list results like:
<a hred=#id>#name</a>
How should I do it ?
It's not the firt time when I'm having this problem.
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

try this:
Assuming your array is called $my_array

Code: Select all

foreach ($my_array as $index => $record)
{
    echo "<a href=\"{$record['id']}\">{$record['name']}</a>";
}
and readup on the foreach construct at http://php.net/foreach

cheers,
Jeffery
Post Reply