php array ထဲက keys ေတြကုိ random ထုတ္ခ်င္တဲ့အခ်ိန္ေတြရွိမွာပါ။
ေအာက္က ပံုစံအတုိင္းသံုးရင္ ဆင္ေျပပါတယ္။
ေအာက္က ပံုစံအတုိင္းသံုးရင္ ဆင္ေျပပါတယ္။
<?php
$cities = array(1 => yangon , 2 => mandalay , 3 => Pathein , 4 => Dawei);
$random_key = array_rand($cities, 1);
print $random_key;
?>
array_rand ဆိုတဲ့ function သံုးရမွာပါ။
$cities က ေတာ့ ကုိယ္သံုးခ်င္တဲ့ array ျဖစ္ျပီး 1 က ေတာ့ ဘယ္ႏွစ္ခုဆြဲမလဲလုိ့ ေရြးရတာျဖစ္ပါတယ္။
အေသးစိတ္ကုိ php.net မွာ သြားဖတ္ႏုိင္ပါတယ္။
Source : http://www.homeandlearn.co.uk/php/php6p7.html
Comments
Post a Comment