2016-10-03 4 views
0

에서 I는이 배열을 주문할제거 널값 키 브로 쌍 distors가 연관 배열

[1] => Array 
    (
     [Assembly required] => Yes 
     [Max load (kg)] => 120 
     [Product weight (kg)] => 
     [Warranty (years)] => 3 
     [Height adjustable] => Yes 
     [Lumbar support] => 
     [Back tilt adjustment] => Yes 
     [Seat tilt adjustment] => Yes 
     [Chair height range (mm)] => 880 - 950 
     [Chair seat width (mm)] => 500 
     [Chair seat depth (mm)] => 480 
     [Chair back height (mm)] => 410 
     [Chair back width (mm)] => 420 
     [Seat height range (mm)] => 440 - 580 
     [AFRDI Approved] => 
     [Optional adjustable arms] => Yes 
     [image] => https://cdn.shopify.com/s/files/1/1249/7859/files/Chair.png?18135080827462508830 
    ) 

상기 어레이의 위해서 var_dump 제가 위에서 블랭크 값 쌍을 제거 할

  [1]=> 
     array(17) { 
     ["Assembly required"]=> 
     string(3) "Yes" 
     ["Max load (kg)"]=> 
     string(3) "120" 
     ["Product weight (kg)"]=> 
     string(0) "" 
     ["Warranty (years)"]=> 
     string(1) "3" 
     ["Height adjustable"]=> 
     string(3) "Yes" 
     ["Lumbar support"]=> 
     string(0) "" 
     ["Back tilt adjustment"]=> 
     string(3) "Yes" 
     ["Seat tilt adjustment"]=> 
     string(3) "Yes" 
     ["Chair height range (mm)"]=> 
     string(9) "880 - 950" 
     ["Chair seat width (mm)"]=> 
     string(3) "500" 
     ["Chair seat depth (mm)"]=> 
     string(3) "480" 
     ["Chair back height (mm)"]=> 
     string(3) "410" 
     ["Chair back width (mm)"]=> 
     string(3) "420" 
     ["Seat height range (mm)"]=> 
     string(9) "440 - 580" 
     ["AFRDI Approved"]=> 
     string(0) "" 
     ["Optional adjustable arms"]=> 
     string(3) "Yes" 
     ["image"]=> 
     string(80) "https://cdn.shopify.com/s/files/1/1249/7859/files/Chair.png?18135080827462508830" 
     } 

이다.

foreach($singlearr as $key=>$value){  
     if(is_null($value) || $value == '') 
      unset($singlearr[$key]); 
    } 

치가 널하지만 순서에 따라 순서를 왜곡이 제거 된 키 - 값 쌍.

[1] => Array 
    (
     [Assembly required] => Yes 
     [Max load (kg)] => 120 
     [Warranty (years)] => 3 
     [Height adjustable] => Yes 
     [Back tilt adjustment] => Yes 
     [Chair height range (mm)] => 880 - 950 
     [Chair seat width (mm)] => 500 
     [Chair seat depth (mm)] => 480 
     [Chair back height (mm)] => 410 
     [Chair back width (mm)] => 420 
     [Seat height range (mm)] => 440 - 580 
     [image] => https://cdn.shopify.com/s/files/1/1249/7859/files/Chair.png?18135080827462508830 
     [Seat tilt adjustment] => Yes 
     [Optional adjustable arms] => Yes 
    ) 

결과 배열 위해서 var_dump 형태 : 예 용

  [1]=> 
     array(14) { 
     ["Assembly required"]=> 
     string(3) "Yes" 
     ["Max load (kg)"]=> 
     string(3) "120" 
     ["Warranty (years)"]=> 
     string(1) "3" 
     ["Height adjustable"]=> 
     string(3) "Yes" 
     ["Back tilt adjustment"]=> 
     string(3) "Yes" 
     ["Chair height range (mm)"]=> 
     string(9) "880 - 950" 
     ["Chair seat width (mm)"]=> 
     string(3) "500" 
     ["Chair seat depth (mm)"]=> 
     string(3) "480" 
     ["Chair back height (mm)"]=> 
     string(3) "410" 
     ["Chair back width (mm)"]=> 
     string(3) "420" 
     ["Seat height range (mm)"]=> 
     string(9) "440 - 580" 
     ["image"]=> 
     string(80) "https://cdn.shopify.com/s/files/1/1249/7859/files/Chair.png?18135080827462508830" 
     ["Seat tilt adjustment"]=> 
     string(3) "Yes" 
     ["Optional adjustable arms"]=> 
     string(3) "Yes" 
     } 

. 위의 결과 배열에서 [image]은 위와 같이 움직입니다.

답변

3
+0

사용이 당신의 널 (null)을 제거하기 위해 ..

이 배열에서 모든 빈과 null 값을 필터링합니다

array_filter()를 사용할 수 있습니다 배열의 값 필드 $ arr = array_filter ($ arr); –

+0

@NaveenKumar @jaimin array_filter()가 빈을 제거 했으므로 검사 할 필요가 없지만 이전 순서가 왜곡됩니다. 나는'CSV' 파일에서 배열을 가져 가고있다. –