Jump to content

"Only variables can be passed by reference"


Recommended Posts

This is an error I never gotten before, and Googling for my specific problem doesn't seem to help. Maybe if I explain what I am doing without the code someone can figure it out, maybe it's just a change between PHP versions and that's all (from what I've seen at least).

 

I have some variables I want random numbers for, but numbers I chose, so it looks something like this:

$variable = shuffle("1", "5", "10", "15", "20");

 

The first line this appears on is the line that says the error. Am I doing something wrong?

Link to comment
Share on other sites

I'm no expert at arrays, but I think if you print_r($variable); you'll see pointers.  something like [0] => 1, [1] =>5 etc.  And I believe you'll need to access these variables by called or "referencing" the pointer.  Maybe this would work.

$variable = array("1", "5", "10", "15", "20");
print_r($variable);

 

Link to comment
Share on other sites

shuffle takes an array as an argument. It randomizes the content in place, so you want something like:

<?php
$variable = array(1,5,10,15,20);
shuffle($variable);
echo '<pre>' . print_r($variable,true) . '</pre>'; //see what's in the shuffled array
?>

 

Ken

Link to comment
Share on other sites

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.