2014-05-12 3 views
0

배열이있는 경우 내 배열 값과 문자열을 비교하고 싶습니다.다차원 배열을 문자열 PHP와 비교

여기에 $ uid = something 값이 있습니다.

내 배열 항목 objectId가 $ uid와 같으면 해당 요소가 새 배열로 이동합니다.

Array 
    (
     [results] => Array 
      (
       [0] => Array 
        (
         [birthday] => 11-Apr-2014 
         [category] => Array 
          (
           [0] => 204 
           [1] => 300 
           [2] => 304 
          ) 

         [city] => fgfg 
         [country] => fgf 
         [email] => [email protected] 
         [fullName] => fg 
         [gender] => Male 
         [inspirational] => Run to dream 
         [phone] => gfg 
         [photo] => Array 
          (
           [__type] => File 
           [name] => 8bef9bc3-ee64-45df-9698-0466e255c1bd-profilePhoto.jpg 
           [url] => http://files.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/8bef9bc3-ee64-45df-9698-0466e255c1bd-profilePhoto.jpg 
          ) 

         [username] => aapbd 
         [website] => http://aahgh.com 
         [createdAt] => 2014-04-10T19:01:16.396Z 
         [updatedAt] => 2014-04-28T07:36:18.459Z 
         [objectId] => IQSCdXE2hI 
        ) 

       [1] => Array 
        (
         [birthday] => 09-Apr-1982 
         [category] => Array 
          (
           [0] => 204 
           [1] => 307 
           [2] => 311 
           [3] => 313 
           [4] => 102 
           [5] => 103 
           [6] => 105 
           [7] => 107 
          ) 

         [city] => Madrid 
         [country] => Spain 
         [coverPhoto] => Array 
          (
           [__type] => File 
           [name] => aa53cf65-47af-464d-aa49-88202f91388f-coverPhoto.jpg 
           [url] => http://files.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/aa53cf65-47af-464d-aa49-88202f91388f-coverPhoto.jpg 
          ) 

         [description] => a lazy man 
         [email] => [email protected] 
         [fullName] => Shghghossain 
         [gender] => Male 
         [inspirational] => Honesty is the best policy 
         [phone] => 135469 
         [photo] => Array 
          (
           [__type] => File 
           [name] => a1aec283-f3c7-484c-a8b2-a0b09c5f3023-profilePhoto.jpg 
           [url] => http://files.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/a1aec283-f3c7-484c-a8b2-a0b09c5f3023-profilePhoto.jpg 
          ) 

         [username] => asa 
         [website] => 
         [createdAt] => 2014-04-09T07:58:19.043Z 
         [updatedAt] => 2014-05-07T11:13:40.671Z 
         [objectId] => iVb6olefaT 
        ) 

     ) 

) 

이 코드를 사용하지만 작동

$ids2 =array(); 
foreach($array_post['results'] AS $i) 
{ 
$ids ='iVb6olefaT'; 

     if(in_array($i['objectId']==$ids)) 
     { 
     $ids2[]=$i; 


     } 
     else 
     { 
     $ids2; 
     } 
} 
+0

'경우 (와 in_array ($ i가 [ 'OBJECTID'는] == $ IDS는))'이다 그 새로운 통용 설탕? – bwoebi

+0

in_array가 필요하지 않습니다. 그냥'if ($ i [ 'objectId'] == $ ids)'입니다. foreach 루프 앞에 $ ids = '...'를 넣을 수 있습니다. 이 방법은 더 깨끗합니다. –

+0

'else {$ ids2}'는 아무 것도하지 않습니다. 그것은 본질적으로 Null 문장입니다. –

답변

0

이 시도 :

$ids2 = array(); 
$ids = 'iVb6olefaT'; 

foreach($array_post['results'] AS $i) 
    if($i['objectId']==$ids) 
     $ids2[] = $i;