php 怎么随机抽取二维数组里的几个数组???
例如:$data=array(array("price"=>"6874","air"=>"国泰"),array("price"=>"4726","air"=>"大韩航空"...
例如:
$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" => "泰国航空"
)
);
怎么取得其中的几组数组??? 展开
$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" => "泰国航空"
)
);
怎么取得其中的几组数组??? 展开
3个回答
展开全部
//你的数组少写了个逗号
$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);
2019-10-30
展开全部
//你的数组少写了个逗号$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);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
array_rand($data,$numbers);
望采纳
看错了 不明白你是要随机取吗?
还是取固定的?
望采纳
看错了 不明白你是要随机取吗?
还是取固定的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询