0
트위터 클래스를 만들고 해당 클래스의 메서드와 속성을 호출하는 객체를 만들려고합니다. 본질적으로 내가하고있는 일은 트위터 사용자 이름에 대해 데이터베이스를 호출하고 그 결과로 simplexml 요청을하는 것입니다. (코드가 잘 작동하기 때문에 그 부분을 생략했습니다).전체 배열이 반환되지 않음 PHP
배열의 첫 번째 항목 만 반환 될 때 return $this->posts
이 반환되는 이유를 알 수 없다는 것을 제외하면 모든 것이 올바르게 작동하는 것처럼 보입니다. return
을 제거하면 전체 배열이 반환됩니다. 맨 아래에있는 객체에 print_r
을 사용하여 테스트하고 있습니다.
<?php
class twitter {
public $xml;
public $count;
public $query;
public $result;
public $city;
public $subcategory;
public $screen_name;
public $posts;
public function arrayTimeline(){
$this->callDb($this->city, $this->subcategory);
while($row = mysql_fetch_row($this->result)){
foreach($row as $screen_name){
$this->getUserTimeline($screen_name, $count=2);
}
foreach($this->xml as $this->status){
return $this->posts[] = array("image"=>(string)$this->status->user->profile_image_url,"name"=>(string)$this->status->name, "username"=>(string)$this->status->user->name, "text"=>(string)$this->status->text, "time"=>strtotime($this->status->created_at));
}
}
}
$test = new twitter;
$test->city="phoenix";
$test->subcategory="computers";
$test->arrayTimeline();
print_r($test->posts);
?>