AnAmericanGunner Posted June 3, 2011 Share Posted June 3, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238279-only-variables-can-be-passed-by-reference/ Share on other sites More sharing options...
Drummin Posted June 3, 2011 Share Posted June 3, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/238279-only-variables-can-be-passed-by-reference/#findComment-1224470 Share on other sites More sharing options...
kenrbnsn Posted June 3, 2011 Share Posted June 3, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238279-only-variables-can-be-passed-by-reference/#findComment-1224506 Share on other sites More sharing options...
AnAmericanGunner Posted June 4, 2011 Author Share Posted June 4, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/238279-only-variables-can-be-passed-by-reference/#findComment-1225105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.