2016-06-08 6 views
0

그래서 현재 특성을 기반으로 데이터를 가져오고 자체 별도의 배열에 데이터를 저장하는 배열이 있습니다. 내가 할 필요가있는 것은이 3 개의 배열을 하나의 배열에 넣는 것입니다. 그래서 만약 그것들 중 하나가 null이라면, 그것은 오류를주지 않을 것입니다. 상당히 간단해야하지만 내 머리를 감쌀 수는 없습니다.PHP에서 배열 서식 지정 (3을 하나로)

//CV eqpValue 
if (is_array(FullDataResponse->dlr->DesignLayoutRecord)) { 
    foreach(FullDataResponse->dlr->DesignLayoutRecord as $DesignLayoutRecord_key => $DesignLayoutRecord_value) { 
      if ($DesignLayoutRecord_value->cktEqpOptions->CktEqpOptions && is_array($DesignLayoutRecord_value->cktEqpOptions->CktEqpOptions)) { 
        foreach ($DesignLayoutRecord_value->cktEqpOptions->CktEqpOptions as $cv_obj) 
          { 
           if($cv_obj->attribute === 'CDR') 
             { 
              $this->cvCDRList[] = array("cdr" => $cv_obj->eqpValue); 
             } 

           if($cv_obj->attribute === 'CUSTOMER') 
             { 
              $this->cvCustomerList[] = array("customer" => $cv_obj->eqpValue); 
             } 

          if($cv_obj->attribute === 'LEASE LINE') 
             { 
              $this->cvphoneList[] = array("phoneNumber" => $cv_obj->eqpValue); 
             } 
             } 
            } 
           } 
          } 

현재 이들이 cvCDRList, cvCustomerList 및 cvphoneList와 같은 별도의 배열에 저장되는 방법을 확인 하시겠습니까? 어떻게 하나의 배열에 넣을 수 있습니까? 감사!!

+0

나는 당신이 무엇인지에 혼란 스러워요 묻고. cvCDRList, cvCustomerList 및 cvphoneList를 newList로 변경하려고합니까? 최종 배열의 형식은 무엇입니까? – bassxzero

+0

네, 맞습니다. "newList"[]가 cvCDRList, cvCustomerList 및 cvphoneList 필드로 구성되기를 바랍니다. 혼란을 드려 죄송합니다. – LeeBronwin

답변

0

array_merge를 사용할 수 있습니다.

<?php 

    $array1 = array("a12","a12","a13"); 
    $array2 = array("a21","a22","a23"); 
    $array3 = array("a31","a32","a33"); 

    $finalArray = array_merge($array1,$array2,$array3);    
    foreach($finalArray as $key => $value){ 
     echo $key."=>".$value."<br>"; 
    } 

?> 

"allAtributes"라는 또 다른 속성을 만들 수 있습니다. 3 개의 배열을 채우기 위해 완성되면 3 개의 배열 사이에서 병합을 만드는 것보다 다른 클래스의 메서드를 호출 할 수 있습니다.

결국이 같은 가지고 것이다

allAtributes (array)=>{ 
     ["cdr"](array)=> { 
      ['cdrkey1'] = cdrAtt1 , 
      ['cdrKey2'] = cdrAtt2 ... 
     }, 
     ["customer"](array)=> { 
      ['customerkey1'] = customerAtt1 , 
      ['customerKey2'] = customerAtt2 ... 
     }, 
     ["phoneNumber"](array)=> { 
      ['phoneNumberkey1'] = phoneNumberAtt1 , 
      ['phoneNumberKey2'] = phoneNumberAtt2 ... 
     } 
} 
+0

정확한 예를 들어 어떻게 사용되는지 알려주시겠습니까? 나는 그것을 시험하고있다. 그러나 그것은 나에게 이슈를주고있다. – LeeBronwin

+0

아, 방금 오류가 발생했습니다. 루프 외부에 있는지 확인해야했습니다. – LeeBronwin

0

당신 만 배열을 선언 루프에 함수 array_merge와 다른 세 개의 배열을 추가해야합니다