一、总结

一句话总结:

也就是array_random 的结果数组不会被打乱
//从推荐课程列表中随机选出 $recommend_lesson_num 个
//计算总课程数量
$now_lesson_num=count($lessons);
if($now_lesson_num>=$recommend_lesson_num){
    $lessons=array_random($lessons,$recommend_lesson_num);
}else{
    $lessons=array_random($lessons,$now_lesson_num);
}

 

 

 

二、array_random 从一个数组中随机去几个,可以保持原数组顺序

博客对应课程的视频位置:

 

//从推荐课程列表中随机选出 $recommend_lesson_num 个
//计算总课程数量
$now_lesson_num=count($lessons);
if($now_lesson_num>=$recommend_lesson_num){
    $lessons=array_random($lessons,$recommend_lesson_num);
}else{
    $lessons=array_random($lessons,$now_lesson_num);
}

 

array_random 从一个数组中随机去几个,可以保持原数组顺序

 

array_random 从一个数组中随机去几个,可以保持原数组顺序

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2021-07-14
  • 2021-11-19
  • 2021-11-16
相关资源
相似解决方案