PHP如何随机获取一个二维数组中的一个值

获取一个数组:

$awardid_list=pdo_fetchall('select id from '.tablename($this->table_award));

这是微擎的写法哈,意思就是查询一组字段为id的数据;

二维数组如图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlQAAABGCAIAAACFe53HAAAFlklEQVR4nO3cPZLbNhgAUN0jM1s6MylScKstXMc74xPId6HOojpnSMETpNoqhQ6QE6RSCokS/wCQK1GiifcGxdqkQCw+gB9A0d68A0BmNs9uAAA8muQHQHYkPwCyI/kBkB3JD4DsSH4AZOea/P759z9FURRFWUGZkPz+/OtvRVEURVlBmZD8jgCwCpIfANmR/ADIjuQHQHYkPwCyk05+L7XLZw77bVEUZfW4VlZl/3JV+VoU13acGlUURbHdHy6fap5xX8vrhKosftS/evOU3eXwfL1x6o9A1YGGnQ699hvVqkoQj8cHBLFuQ7Dy8UEcqEoQj8cHBPF6DwzUHQ1i8NBqvaRsvtfqj1Tla7F9216TzMwCt9VmtA77bWvuXZsWuSffZIGdEFBPuUgtd2ldbDYf9tvhjuq3f6gqQZw3iK0p05xLLaOCGK5KEGeeiVXZ2gkM90cwiNFDK/U9pZf8TiE87Ldvza467Lfb/b6st16dP7YWJZdbWyNa5ypCoyqxFO00ptq159/oQTY+/AvshN496HzdffnJKTeuN86/07YsX2NVV+XgbGzdMoJVCeKsQWzelLtt6DY0EcRIVYI4axDbPRDOfqEgJg6t0uTkV3dQp3sP+23R2XA1/lg1b2dVWY+31lQZHg7hQdKecp2RHx9k1a7o2jamaPqJxBI74fpzs1WnuTdnb1S7Kt7Gy1UGJlb7PhuqShDnDmKnoW+hG+eIIIaqEsTHBTGS+0JBTB1ao4nJrzGa249HBgZfrPcvi63LKAwPtvAK5se1JZ3kF59ySfUeJDmll9MJ1587q+/bH7bEe6NxUjxJDt0iB/9yXPJLEsTu9ZNBPHY7I9bU+F/2qhLERwSx3tLG4uybv7Npya8d/OYCqhPM4YXN8DfhZRX6QGeN1j00X/LrXaJpmZ1w+XmgN+7zTUN8YiSrDvTGfMkvdglBHBTPfKFrB4PYOlUQHxTE0ym7cCAj176pWT+dScmvOVw6+/L4aDt/8HzuwAroI9Dp4xYpd3zsef1UaPm01E749JS7qTdCv+zwCb0qbkh+gni33riekNoYjgviYFWC+KCZGLnA9VB4K53Rg88pya+/mqh2dSSio62TnPrP1vehSI1banXH9mdfeDmOeLa+2E6Y42FLsjfapy5l5yeITWOCeP3103UlghiqShBnDWL/VaNgU+38ziYkv87bUMfjsbFSSI22VtRbi5doWEc+ZG8+Y7nhnzoc0m9VLbgTWl+zN3tj1rc9m42M318f9J2fIHYuO/FFwahUECNVCeK8MzGa4INNHX9ohSYkv8FhXYf3IzbaTiP1rKyOH61VSXOE9IQHSSdO50HbfShw36VMYG4voxN6q4FTZ3z6BetpUlVPeFHw5p1fnCD2G9YTaGkiiLGqBHH2mdjo/kiy9LZnbcpjz5kkxkFoMTJukfKz7ONn7YSxV5lR+p+IRQjihKvMSBDXG8TEoVV6fvJL7ukD42RVU27eTkjVMrvgryeIR0FclFyDOPVrjjV4avI7bdOnPs4+G/xvITtnxB7hLMXMndA49Vm9Ef2OQRAFcSEyD2JO3/adPH/nBwAPJvkBkB3JD4DsSH4AZEfyAyA7kh8A2ZH8AMiO5AdAdiQ/ALIj+QGQnXTye6k9u6kAcB8vKZv32rObCgD38Z4i+QGwNpIfANmR/ADIjuQHQHYkPwCyI/kBkB3JD4DsSH4AZEfyAyA76eS3+XIuz24qANyHnR8A2RmV/Irf7fwAWA+PPQHIzpidX/HLb79+9dgTgLUYl/zs/ABYETs/ALJj5wdAdsYkv7NnNxUA7iOd/LztCcDKSH4AZMdjTwCyI/kBkJ0JyQ8AMiH5AZAdyQ+A7Eh+AGRH8gMgO5uvAJCZzbdvfyiKoihKVkXyUxRFUbIrkp+iKIqSXfkfE2v2qwJh6pQAAAAASUVORK5CYII=" alt="" />

那么值是1、2、3,我们如何随机获取呢,请往下看代码:

$no=array_rand($awardid_list);
print_r($awardid_list[$no]['id']);

这样就OK了哈,就可以随机获取值1、2、3了哦。

上一篇:C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件)的解决方法


下一篇:Java基础知识回顾之五 ----- 多线程