2010-12-09 5 views
1

내 위해서 var_dump는 다음과 같습니다

array(1) 
     { [0]=> object(stdClass)#102 (9) { 
      ["term_id"]=> string(2) "17" 
      ["name"]=> string(5) "Image" 
      ["slug"]=> string(5) "image" 
      ["term_group"]=> string(1) "0" 
      ["term_taxonomy_id"]=> string(2) "19" 
      ["taxonomy"]=> string(18) "gallery" 
      ["description"]=> string(0) "" 
      ["parent"]=> string 
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus et    tempus tellus. Integer euismod, est et ultricies tristique, urna ipsum    semper elit, pharetra cursus ligula turpis sed libero. Vestibulum ante    ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;    Suspendisse pellentesque orci sed tellus hendrerit a auctor augue    commodo. Ut nibh lacus, … 
      Read more... 
      (1) "0" 
      ["count"]=> string(1) "1" 
      } 
     } 

내가 (나는 "이미지를"에코 할이 경우) 내부에서 데이터를 얻는 데 문제가 있어요. 예를 들어

$ 갤러리 [] 출력

Fatal error: Cannot use [] for reading in [source file url]

$ 갤러리 [0]

Catchable fatal error: Object of class stdClass could not be converted to string in [source file url]

$ 갤러리를 나타낸다 [1], $ 갤러리 [2] 등 비어.

내가 아는 한 PHP $ gallery [0] [3]은 작업을 수행해야하지만, stdClass 객체를 반향시킬 수 없다면 어떻게해야합니까? :/$ gallery [0] [ 'slug']도 유효한 btw입니까?

고마워요.

예 - 배열의 첫 번째 항목을 변경할 수 없습니다. Wordpress에서 생성되었지만 엄격한 PHP 질문이기 때문에 여기에서 묻습니다.

건배.

답변

5

$gallery은 하나의 객체가 StdClass 인 배열입니다.

$gallery[0]->slug; 
+0

내 주인에게 감사하십시오! $ gallery [0] [slug]와 #gallery [0] -> slug의 차이점은 무엇입니까? – anonymous

+2

배열 인덱스에'[]'가 사용되고 객체의 접근 메소드/멤버에'->'가 사용됩니다. '$ gallery [0]'은 객체이므로'->'를 사용하십시오. – meagar

+1

슬러그는 객체 속성이므로 $ gallery [0] [slug]가 작동하지 않으면 속성으로 사용해야합니다. $ gallery [0] [ 'slug']는 – RusAlex

-1

전체 이송 같은 : 도움이 :) 그리고 내부, 첫 번째를 얻을 수

foreach ($gallery as $key=>$value) 
{ 
    print $key; 
    print $value; 
} 

희망

당신은 인덱스 0에서 개최 된 개체의 slug 멤버에 액세스 할 $ key-> image처럼 $ key->

+0

일 것입니다. -1로해야합니다. 이것은 잘못되었습니다. '$ gallery [0]'을 출력하려고 할 때와 같은 오류가 발생할 것입니다. 문제는 개체를 문자열로 변환하는 것입니다. 바로 문자열을 처리하려고합니다. – meagar