2014-10-13 6 views
-1

나는 각 항목의 개별 값을 좀하고 싶습니다이 배열은 한 :PHP는 배열의 값을 얻는 것은

이것은 내가 하나에서 얻을 수 print_r($theme_option):

Array ([side_bars] => Array ([0] => Array ([title] => Left Page Sidebar [sort] => 0) [1] => Array ([title] => Right Page Sidebar [sort] =>) [2] => Array ([title] => Left Blog Sidebar [sort] =>) [3] => Array ([title] => Right Blog Sidebar [sort] =>)) 

의 결과입니다 사용하여 사이드 바 이름 :

$theme_option['side_bars'][0]['title']; 

내가 통해 루프를 시도하고이 코드를 사용하여 각각의 사이드를 얻을 수 있지만 예상대로 반환하지 않습니다.

global $theme_option; 

    if(isset($theme_option['side_bars']) && is_array($theme_option['side_bars'])){ 
     foreach ($theme_option['side_bars'] as $key => $value) { 
      $theme_side_bars["$key"] = "$value"; 
     } 
    } 

내가하려고하는 것은 각 "사이드 바"의 값을 가져 와서 "제목"을 드롭 다운 상자에 넣는 것입니다.

감사

답변

1

모든 특별한 정보를 사용해, 배열을 포함하는 배열 side_bars 있습니다.

이 코드를 사용하면 모든 제목이 변수 $theme_side_bars에 저장되어있는 배열을 가져야합니다.

global $theme_option; 
$theme_side_bars = array(); 
if(isset($theme_option['side_bars']) && is_array($theme_option['side_bars'])){ 
    foreach ($theme_option['side_bars'] as $index=>$arr) { 
     $theme_side_bars[] = $arr['title']; 
    } 
} 
+0

대단한 설명과 도움에 감사드립니다. – Jason

관련 문제