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条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题