random values

trouble using the array_rand()

Page 1 of 1

3 Replies - 642 Views - Last Post: 08 September 2008 - 08:47 AM Rate Topic: -----

#1 jamessy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 15-April 08

random values

Post icon  Posted 08 September 2008 - 05:50 AM

Hi all im having a bit of trouble i want to show the values of an array instead of the keys any help would be grateful
heres the code






		


$array = array('helllo','more','testing','welcome');
list($one,$two,$three,$four)=array_rand($array,2);

echo $one;
echo $two;


















Is This A Good Question/Topic? 0
  • +

Replies To: random values

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: random values

Posted 08 September 2008 - 06:49 AM

Just echo out the value instead of the key.
echo $array[$one];
echo $array[$two];


Was This Post Helpful? 0
  • +
  • -

#3 jamessy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 15-April 08

Re: random values

Posted 08 September 2008 - 06:55 AM

View PostAdaHacker, on 8 Sep, 2008 - 06:49 AM, said:

Just echo out the value instead of the key.
echo $array[$one];
echo $array[$two];


thanks Adam you made it look easy lol
Was This Post Helpful? 0
  • +
  • -

#4 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: random values

Posted 08 September 2008 - 08:47 AM

or use print_r() instead of echo
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1