当前位置 : 主页 > 网络编程 > PHP >

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

来源:互联网 收集:自由互联 发布时间:2021-06-30
随机出来数组序号,然后再去组合数组 1. [代码] [PHP]代码 //百度知道中的代码,mark一下$data = array( array( "price" = "6874","air" = "国泰" ), array( "price" = "4726","air" = "大韩航空" ), array( "price" = "65
随机出来数组序号,然后再去组合数组

1. [代码][PHP]代码    

//百度知道中的代码,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);
//分享自 
网友评论