pilots Posted January 28, 2008 Report Share Posted January 28, 2008 <?php $input = array('xxx', 'yyy', 'zzz'); $rand_keys = array_rand($input, 1); echo $input[$rand_keys['0']] . "\n"; ?> vai <?php $input = array('xxx', 'yyy', 'zzz'); shuffle($input); echo $input[0] . "\n"; ?> ir kāds vēlamāks par otru variants? Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2008 Report Share Posted January 29, 2008 Nevajag padot stringu tur, kur vajadzīgs integers. Un nevajag lieki konkatenēt stringus. <?php $input = array('xxx', 'yyy', 'zzz'); $rand_keys = array_rand($input, 1); echo $input[$rand_keys[0]], "\n"; ?> Link to comment Share on other sites More sharing options...
pilots Posted January 29, 2008 Author Report Share Posted January 29, 2008 Notice: Undefined index: in ... rindiņā - echo $input[$rand_keys[0]], "\n"; kā tad to izlabot? Link to comment Share on other sites More sharing options...
Val Posted January 29, 2008 Report Share Posted January 29, 2008 echo $input[$rand_keys], "\n"; Link to comment Share on other sites More sharing options...
pilots Posted January 29, 2008 Author Report Share Posted January 29, 2008 Paldies, Val. Tagad strādā ok tas skripts. Link to comment Share on other sites More sharing options...
Recommended Posts