2014-11-20 2 views
1

작은 다른 질문 (이전 here)추출물 값

나 루프를 필요로하는 배열이 있다면?

/* 
Array 
(
    [0] => Array 
     (
      [email] => example email 
      [reason] => hard-bounce 
      [detail] => 550 mailbox does not exist 
      [created_at] => 2013-01-01 15:30:27 
      [last_event_at] => 2013-01-01 15:30:27 
      [expires_at] => 2013-01-01 15:30:49 
      [expired] => 
      [sender] => Array 
       (
        [address] => [email protected] 
        [created_at] => 2013-01-01 15:30:27 
        [sent] => 42 
        [hard_bounces] => 45 
        [soft_bounces] => 47 
        [rejects] => 42 
        [complaints] => 42 
        [unsubs] => 42 
        [opens] => 42 
        [clicks] => 42 
        [unique_opens] => 42 
        [unique_clicks] => 42 
       ) 

      [subaccount] => example subaccount 
     ) 

) 

은 내가 어떻게 더 라인에서 얻을 수있는이 같은

? 같은

: 내가 유 모든 사람을 사랑

  1. [email protected], 45
  2. [email protected], 45

는, u는 나에게 많은 도움이!

+0

질문 무엇입니까? 어떻게 루프 물마루 배열? – Rizier123

+0

편집 질문 : 목록 –

답변

1
echo '<table>'; 
foreach($array as $key => $subArray) { 
    echo '<tr><th>' . $key . '</th><td>' . $subArray['email'] . '</td><td>' . $subArray['sender']['hard_bounces'] . '</td><td>' . $subArray['reason'] . '</td><td>' . $subArray['detail'] . '</td></tr>'; 
} 
echo '</table>'; 
+0

와우 그 작품! –

+0

물론입니다 : p http://php.net/manual/en/control-structures.foreach.php – RichardBernards

+0

에서 'foreach()'를 사용하여 읽으십시오. ex 키를 행으로, 'reason'과 'detail'을 열로 사용합니다. :) –

-4

array_map 기능은 구조에 온다 :

implode(', ',    // will prepare a string from array 
    array_map(function($el) { // will map existing array to new values 
    $result = array();  // prepare result 
    foreach(array('email', 'reason') as $name) { // select only email and reason fields 
     $result[$name] = $el[$name];    // setup result 
    } 
    return $result;   // return to map 
    }, $array) 
); 
+0

같은 출력이 더 제발 도와왔다 나는이 코드를 공부하고 있습니다) ... 는 $는 nameofarray - 내가해야합니까 을 반향하는 결과이다 - $ resultofmapping 내 배열 입니다 이거 넣어? –

+0

업데이트로 의견보기 – mudasobwa

+0

이것은 나쁜 코드 일뿐입니다. array_map 내에서 반복 실행은 전혀 필요하지 않습니다. 이 경우뿐만 아니라 어떤 경우에도. –