I have learned php this summer so i am pritty new and need some help.

what i am trying to do is that i have an item with an item# and a lot of other info from my db and would like to transfer that info in the array in a way so that when i select an item # it would display item# aswell as the data that was put in an arry. what command or how would i do that.

Thanks

Well, from your post, I'm unclear as to what exactly you want to do, but I hope this helps:

<?php
$var = array('1' => 'foo'
             '2' => 'bar'
             'heh' => 'Hello, World!');
echo $array['1'] . '-' . $array['2'] . '-' . $array['heh'];
// The following would echo 'foo-bar-Hello, World!';
?>

i think i can sove it but what i really wanted to know is that is it possible to have more then one result to an key like in your example if i told array to display 1 it would display foo As item name and item#.

Man, I love Sp!ke's posts. He posts beautiful PHP code with excellent comments. Message to all--don't forget to use the post rating system to thank people who help you.

Ashneet, I think what you want is simply an array of arrays. PHP does not support true multi-dimensional arrays, but an array of arrays will fit the bill.

Put this code into a new PHP file and try it:

<?php

$items = array(
  1=>array('name'=>'apple','color'=>'red','price'=>0.50)
  ,2=>array('name'=>'orange','color'=>'orange','price'=>0.60)
  ,3=>array('name'=>'banana','color'=>'yellow','price'=>0.35)
  );

echo "<pre>";
print_r($items);
echo "</pre>";

?>

Will output:

Array
(
    [1] => Array
        (
            [name] => apple
            [color] => red
            [price] => 0.5
        )

    [2] => Array
        (
            [name] => orange
            [color] => orange
            [price] => 0.6
        )

    [3] => Array
        (
            [name] => banana
            [color] => yellow
            [price] => 0.35
        )

)

So you can access individual items like so:

echo $items[2][color];

Of course you would build your array dynamically from your database query.

Thanks That make sense and it helped as that will do the job really well

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.