SirChick Posted October 11, 2007 Share Posted October 11, 2007 I have a random array and when i echo the value that the array chooses it seems to be empty..... I'm not sure why.. i purposely only put one choice for testing purposes and it still won't do it.... this is what i have: $PercentageAddOn = array(); //$PercentageAddOn[] = 2.62; //$PercentageAddOn[] = 52421; //$PercentageAddOn[] = 51; $PercentageAddOn[] = 1.32; //$PercentageAddOn[] = 4.72; //$PercentageAddOn[] = 9.72; //$PercentageAddOn[] = 0.2; //$PercentageAddOn[] = 0.72; //$PercentageAddOn[] = 0..9; $PercentageKey = array_rand($PercentageAddOn); $PercentageAddOn = $PercentageResults[$PercentageKey]; The result should be $PercentageAddOn[] = 1.32; but when echo'd it doesn't show anything....Any one know why? It did used to work but I don't know why but its decided not to work. =/ Link to comment https://forums.phpfreaks.com/topic/72780-solved-random-doesnt-pick-a-value-anymore/ Share on other sites More sharing options...
otuatail Posted October 11, 2007 Share Posted October 11, 2007 $PercentageAddOn = $PercentageResults[$PercentageKey]; first you don't have square brackets for $PercentageAddOn second you seem to be adding an item out of array $PercentageResults to $PercentageAddOn $PercentageResults[1.32] is not a valid aray position. Link to comment https://forums.phpfreaks.com/topic/72780-solved-random-doesnt-pick-a-value-anymore/#findComment-367044 Share on other sites More sharing options...
Cagecrawler Posted October 11, 2007 Share Posted October 11, 2007 $PercentageAddOn = $PercentageResults[$PercentageKey]; should be: $PercentageResults = $PercentageAddOn[$PercentageKey]; Now, $PercentageResults would be equal to 1.32 Link to comment https://forums.phpfreaks.com/topic/72780-solved-random-doesnt-pick-a-value-anymore/#findComment-367048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.