Jump to content

Recommended Posts

I should know this, but i'm having a bad day.  :(

 

If I have:

 

		$s = array();	
	$s[0] = "blah.";
	$s[1] = "blah blah.";
	$s[2] = "more blah.";


	echo array_rand($s,1);

 

Why it return a random number and a warning:

Warning: array_rand() [function.array-rand]: First argument has to be an array in [filename here] on line 140

 

I'm just trying to pull a random element from the array without using a complex formula. Now I've done this before but damn, like I said, my day has been full of sh*t.

 

Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/207786-quick-array-question/
Share on other sites

Try this:

 

<?php
$s = array("blah.", "blah blah.", "more blah.");
$rand = array_rand($s);
echo $s[$rand];
?>

 

Excellent, man. It works. Thank you very much.. solved :]

 

And Pickachu, you're right as well. Don't mind me i'm in my own little worldddd. Sorry for wasting you folk's time.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.