2011-04-14 3 views
0

두 가지 질문이 있습니다 : 1. 시작 문자열과 끝 문자열을 사용하여 문자열을 배열로 나누는 방법으로 배열 요소를 모두 inbetween에서 제거합니다. 2. 새 배열을 다른 배열과 비교하고 요소가 일치하면 사용자가 일치하는 값을 알 수 있습니다.문자열 배열을 만들어 다른 배열과 비교하십시오.

은 내가 MAC 주소의 값을 필요 배열로 문자열의 내용을 깰 필요가

[MAC] 
mac=12EG23OCSOPC 
mac=111111111111 
mac=222222222222 
mac=333333333333 

나는 "= 맥"후 모든 값을 필요로하고 \ n을 이전

그리고 나서이 값을 다른 배열과 비교해야합니다. 동일한 항목이있는 경우 사용자에게 일치하는 항목을 알려줘야합니다. 이것은 내가 지금까지 가지고있는 것입니다.

function count_compare_macs($macs_to_compare, $new_array) 

{ 
    $macs_to_compare_count = count($macs_to_compare); 
    $new_array_count = count($new_array); 

     if(($macs_to_compare_count + $new_array_count) >= 5) 
      { 

      return false; 
        $error_message="You already have 5 MAC address in your system"; 
      }else{ 
       //here is where i need to compare the two arrays and if any are the same say false and set the error message. 
         $compare_arrays = array_Diff($macs_to_compare,$new_array) 
         if (!$compare_arrays){ 
           return true; 
           }else{ 


//here is where i need to compare the two arrays and if any are the same say false and set the error message. 
             $error_message= "The following mac is already used" . $match 
return false; 
             } 
       } 
    } 

답변

1

는 # 1를 위해 무엇을 할 수 있습니다 : http://codepad.org/Taiyrvf2
(즉, 데모에 내가 \r\n에 의해 제 1 부분을 폭발했다 있기 때문에 여기

$str = "mac=12EG23OCSOPC 
mac=111111111111 
mac=222222222222 
mac=333333333333"; 

$strSplode = explode("\n",$str); 

$mac = array(); 

foreach($strSplode as $m){ 
    list($temp, $mac[]) = explode("=", $m); 
} 

은 파트 1의 데모입니다

,853,469,321 : 그것은 모두 2 부분

) 문자열 인코딩 방식에 따라 어떤 선에 의해 분할되었다, 0

+0

도움을 주셔서 감사합니다. 나는 성냥에 기초를 두는 새로운 배열을 만드는 경우에 결코 생각하지 않는다. 매우 도움이됩니다. – Denoteone

+0

아무 문제 없음^_^언제든지 – Neal

관련 문제