Home > php教程 > PHP源码 > body text

输出数组中的随机几组数组

WBOY
Release: 2016-06-02 09:14:15
Original
1214 people have browsed it
跳至 [1] [全屏预览]
//百度知道中的代码,mark一下
$data = array(
            array(
                "price" => "6874","air" => "国泰"
            ),
            array(
                "price" => "4726","air" => "大韩航空"
            ),
            array(
                "price" => "6569","air" => "国泰航空"
            ),
            array(
                "price" => "6569","air" => "卡塔尔航空"
            ),
            array(
                "price" => "3380","air" => "美国航空"
            ),
            array(
                "price" => "4200","air" => "泰国航空"
            )
    );
//随机选择出两个元素
$temp=array_rand($data,2);
//重组数组
foreach($temp as $val){
    $data_last[]=$data[$val];
}
print_R($data_last);
//分享自 
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!