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?

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);

 

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

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

 

Once I changed it to this it worked, thanks!

Archived

This topic is now archived and is closed to further replies.

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