php - PHP with two FOR loops
问题描述
I have two "for" loops
First for is to get year range between 1990 and 2019, and the for inside it have to run my script five times with the same year. Example
for($i=1990;$i<2019,$i++){
for($j=1;$j<5;$j++){
$film = "API";
$sve = file_get_contents($film);
$data = json_decode($sve);
foreach($data->results as $key => $value){
$filmovi .= $value->title . ",";
}
}
So, it must run five times in one year, like
1990 - 1,2,3,4,5
1991 - 1,2,3,4,5 etc etc..
Any suggestions?
解决方案
The way you have it, will only run 4 times for each year and exclude 2019. Change your limits on the for loops:
for($i=1990;$i<=2019,$i++){
$filmovi = "";
for($j=1;$j<=5;$j++){
$film = "API";
$sve = file_get_contents($film);
$data = json_decode($sve);
foreach($data->results as $key => $value){
$filmovi .= $value->title . ",";
}
}
}
推荐阅读
- r - 创建大量新向量的问题
- python-3.x - 无法解决 IndexError,将行值与接下来的 2 行进行比较时
- google-apps-script - 如何解锁 Google Apps 脚本中的“挂锁”应用程序脚本文件?
- r - 根据另一列中的值分配方向
- error-handling - 使用机器人框架在登录脚本中添加电子邮件和密码
- swift - 服务器端 Swift Vapor - 模型继承
- c# - 我们可以从 C# winform 运行索引重建或重组命令吗?
- c# - WPF 用户控件依赖属性未绑定
- python - 由于传递给 __init__() 的附加参数,django 中的嵌套视图给出了 TypeError
- java - 方法不会从其超类覆盖