首先,你可以從自己的帖子看到,$obj[1]
是一個數組,這意味着在$obj
變量的所有元素最有可能陣列也是如此。不幸的是,你不能只是echo
一個數組,但通過它進行迭代,以獲得echoable數據,像這樣:
<?php
$jobsHTML = "";
for($i = 0; $i < $max;$i++){
if(!$jobsStillExist){ // CONDITION TO CHECK IF JOBS STILL EXIST
echo "jobs not found";
continue;
}
// SINCE, $obj[$i] COULD BE AN ARRAY,
// YOU NEED TO CHECK THE TYPE 1ST.
// IF IT IS A STRING, APPEND IT AS A STRING TO $jobsHTML
// OTHERWISE, LOOP THROUGH IT TO GET IT'S CONTENT...
$foundJob = $obj[$i];
if(is_array($foundJob)){
foreach($foundJob as $jobData){
$jobsHTML .= $jobData["title"] . "<br />";
$jobsHTML .= $jobData["placement"] . "<br />";
$jobsHTML .= date("d/m/Y", strtotime($jobData["date"])) . "<br />";
$jobsHTML .= $jobData["time"] . "<br />";
$jobsHTML .= $jobData["website"] . "<br /><br />";
}
}else if(is_string($foundJob)){
$jobsHTML .= $foundJob . "<br /><br />";
}
}
echo ($jobsHTML);
發佈您的代碼完全 –
'$ OBJ [$ i]'是一個數組,所以'$ job_found '也是一個數組。 –
粘貼你的'數組'也是什麼'$ max'? – user1234