doujing2017 2016-02-03 10:08
浏览 45
已采纳

SimpleXML期待数组错误PHP

ok below is my code

<?php
// Last 10 Jobs
function last10IT(){
$xml = simplexml_load_file('http://www.cv-library.co.uk/cgi-bin/feed.xml?affid=101899');


$new_array = array();
//$limit = 5;
//$c = 0;
foreach ($xml->jobs->job as $job) {
//    if ($limit == $c) {
//        break;
//    }
    $jobref = $job->jobref;
    $title = $job->title;
    $date = $job->date;
    $new_array[$jobref.$date] = array(
        'jobref' => $jobref,
        'date' => $date,
        'title' => $title,
        'salary' => $job->salary,
        'location' => $job->location,
    );
}
}
ksort($new_array);
$showl = 10;
$n = 0;
foreach ($new_array as $date => $listing) {

    print $listing['title'] . PHP_EOL;

}
?>

All I want it to do is filter by category & display a max of 10 results for example IT so is there a way I can pass the category value into the function that I want it to filter by instead of having to replicate for each category

All I get is :

Warning: ksort() expects parameter 1 to be array, null given in C:\wamp\www\RECRUITMENTFAIR\functions.php on line 28

Please help guys

It something SO simple causing this error but its driving me mad because I just cannot see it

  • 写回答

2条回答 默认 最新

  • duanboshi1472 2016-02-03 10:26
    关注

    it is relative simple: you try to use the variable $new_array out of scope: it is defined within your last10IT() function, but the function ends after the first foreach.

    you should either return the array and call the function to get the array or move the part with the ksort and the printing into the function, depending on your needs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里