We help IT Professionals succeed at work.

php 5.3 array_rand() not working?

Loganathan Natarajan
on
912 Views
Last Modified: 2012-05-10
I have php 5.3 version hosting and trying to achieve the result from array_rand().. it is not working....

the below example is not displayed randomly item ...but it works in php 5.2 version, i checked it....


<?php
	$inventory_Subtitle = array('60 DAY ; Both Ways!  Cover %  Returns!',
										 'PAY LESS;  ! 100% Natural Diamonds!',
										 'FREE Shipping;  Ways! Enter to  Out More!',
										 ': These Diamonds are 100%  & NON !',
										 'Highest Quality;  Prices! .',
										 '100% ; HIGH  NON Enhanced Diamonds!',
										 'BEST  on  for 100% Natural !',
										 'BEST  for  Natural !  Us.');
										 
			$rand_keys 		= array_rand($inventory_Subtitle,8);
			
			
			echo $inventory_Subtitle[$rand_keys[0]];
									 	

?>

Open in new window

Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

Commented:
"is not working" does not give us much to go on if we are going to try to help you.   What happens?  Loop?  Wait?  Incorrect out?  Halt and catch fire?
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Author

Commented:
it always displays only one value .. i. e **60 DAY ; Both Ways!  Cover %  Returns!**

it does not return random values ... i mean another value etc.,
Most Valuable Expert 2011
Author of the Year 2014

Commented:
The code I posted returns random values.  It is not a PHP 5.3 problem.  Please check the man pages in the comments section of the code snippet.

best regards, ~Ray
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Author

Commented:
thanks, it worked out
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.