개체가 Thread_category
입니다. 이 메서드는 이라는 메서드를 사용하여 범주가 $category
인 스레드 배열을 출력합니다.Foreach 루프가 배열을 예상대로 출력하지 않습니다.
Array ([0] => Allergic diseases [1] => Allergic asthma [2] => Congenital lung disease [3] => Idiopathic pulmonary fibrosis)
을 지금, 나는이
$test1 = Thread_category::find_all_by_category('Allergic diseases');
print_r($test1);
echo "<br/>";
echo "<br/>";
$test2 = Thread_category::find_all_by_category('Allergic asthma');
print_r($test2);
echo "<br/>";
echo "<br/>";
$test3 = Thread_category::find_all_by_category('Congenital lung disease');
print_r($test3);
echo "<br/>";
echo "<br/>";
$test4 = Thread_category::find_all_by_category('Idiopathic pulmonary fibrosis');
print_r($test4);
echo "<br/>";
echo "<br/>";
내가하지만
Array ([0] => Thread_category Object ([id] => 2 [thread_id] => 145 [category] => Allergic diseases) [1] => Thread_category Object ([id] => 10 [thread_id] => 146 [category] => Allergic diseases) [2] => Thread_category Object ([id] => 20 [thread_id] => 147 [category] => Allergic diseases))
Array ([0] => Thread_category Object ([id] => 21 [thread_id] => 147 [category] => Asthma) [1] => Thread_category Object ([id] => 24 [thread_id] => 148 [category] => Allergic asthma))
Array ([0] => Thread_category Object ([id] => 4 [thread_id] => 145 [category] => Congenital lung disease) [1] => Thread_category Object ([id] => 22 [thread_id] => 147 [category] => Congenital lung disease) [2] => Thread_category Object ([id] => 25 [thread_id] => 148 [category] => Congenital lung disease))
Array ([0] => Thread_category Object ([id] => 5 [thread_id] => 145 [category] => Idiopathic pulmonary fibrosis) [1] => Thread_category Object ([id] => 11 [thread_id] => 146 [category] => Idiopathic pulmonary fibrosis))
을받을 수 있나요 경우 :
나는 출력 배열 $category_array_for_this_thread
있다!
내가 만약 내가이 얻을이
foreach($category_array_for_this_thread as $category){
echo $category . "<br/>";
$test_array = Thread_category::find_all_by_category($category);
print_r($test_array);
}
....
Allergic diseases
Array ([0] => Thread_category Object ([id] => 2 [thread_id] => 145 [category] => Allergic diseases) [1] => Thread_category Object ([id] => 10 [thread_id] => 146 [category] => Allergic diseases) [2] => Thread_category Object ([id] => 20 [thread_id] => 147 [category] => Allergic diseases))
Allergic asthma
Array ()
Congenital lung disease
Array ()
Idiopathic pulmonary fibrosis
Array ()
내가 볼 수있는 유일한 차이점 두 번째는 foreach 루프에서 것입니다. 내가 3 개 빈 배열
다음방법입니다 ....
public static function find_all_by_category($category) {
return self::find_by_sql("SELECT * FROM thread_category WHERE category='{$category}'");
} foeach 루프에서
Floris 편집을 해주셔서 감사합니다. – GhostRider
'find_all_by_category' 메소드가 전역 변수'$ category' 또는'$ category_array_for_this_thread'에 접근합니까? – fluminis
$ category를 에코로 만들어서 제작 내용을 확인할 수 있습니까? 어쩌면 코드의 더 많은 컨텍스트를 보여줄 수 있습니까? – johnny