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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b