Deepcrawl.php
<?php
$array_issues[] = 0;
$issues = array("thin_pages_basic","not_in_sitemaps_primary_indexable_basic","duplicate_titles_2_basic","pages_with_duplicate_titles_basic","max_external_links_basic","4xx_errors_basic");
for($i=0;$i<6;$i++){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"Your Api key". $issues[$i]);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token:91PB_EP-LSaTVcm2bCjWyE9oLBEhGYSpvuW-gILR1eCEiK-VPL4YO40L8hTFTnepC8HjaLgn2C3AG6k3iv_-zg'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output2 = curl_exec ($ch);
curl_close ($ch);
$results = json_decode($server_output2);
$j=0;
// to get each object from an array of object
foreach((array)$results as $result){
if($j==3)
$array_issues[$i] = $result;
$j++;
}
}
?>
在视图文件中显示
<tr>
<td style='color:#e86363'>" . $array_issues[0] . "</td>
<td style='width:50px'></td>
<td>Thin Pages</td>
</tr>
<tr>
<td style='color:#e86363'>" . $array_issues[1] . "</td>
<td style='width:50px'></td>
<td>Primary Indexable Pages Not in Sitemaps </td>
</tr>
<tr>
<td style='color:#e86363'>" . $array_issues[2] . "</td>
<td style='width:50px'></td>
<td>Duplicate Title Sets</td>
</tr>
<tr>
<td style='color:#e86363'>" . $array_issues[3] . "</td>
<td style='width:50px'></td>
<td>Pages with Duplicate Titles</td>
</tr>
<tr>
<td style='color:#e86363'>" . $array_issues[4] . "</td>
<td style='width:50px'></td>
<td>High External Linking</td>
</tr>
<tr>
<td style='color:#e86363'>" . $array_issues[5] . "</td>
<td style='width:50px'></td>
<td>Broken Pages (4xx Errors)</td>
</tr>
想知道何时在视图文件中声明该错误Undefined offset: 1
但是当我将数组从[1-5]更改为[0]时,它可以正常工作,但是根本没有任何数据吗?如果您知道是什么原因造成的,则在下面发帖确实会有所帮助。谢谢! :)
答案 0 :(得分:1)
首先,将您的$array_issues
声明更改为其中一个
$array_issues = array();
或
$array_issues = [];
然后,我不知道您在这方面要完成什么:
$results = json_decode($server_output2);
$j=0;
// to get each object from an array of object
foreach((array)$results as $result){
if($j==3)
$array_issues[$i] = $result;
$j++;
}
但是,我认为这不能正确初始化您的$array_issues[0]
索引,它甚至可能没有输入……我至少会在if和foreach之外初始化索引,例如:>
$j=0;
// to get each object from an array of object
$array_issues[$i] = ""; // MAKING SURE THIS IS AT LEAST DEFINED.
foreach((array)$results as $result){
if($j==3)
$array_issues[$i] = $result;
$j++;
}
此外,我认为您可以使用$ key => $ value语法而不是该$ j计数器来完成您要执行的操作...
$array_issues[$i] = ""; // MAKING SURE THIS IS AT LEAST DEFINED.
foreach((array)$results as $key => $result){
if($key==3)
$array_issues[$i] = $result;
}