title: Reading from a PHP array in JQuery
body: <p>I seem to have trouble with getting data from a php array, I've looked at various examples of how to do this but I must be missing something because I can not get my code to work.</p>
  
  <p><strong>PHP method</strong></p>
  
  <pre><code>function getLatestActivity(){
     $messages = array( 
        array('id'=&gt;'01', 'value'=&gt;'blah'),
        array('id'=&gt;'02', 'value'=&gt;'Oil'),
        array('id'=&gt;'03', 'value'=&gt;'Spark') 
     );
  
     echo json_encode($messages); 
     return;  
  }
  </code></pre>
  
  <p><strong>AJAX get functiom</strong></p>
  
  <pre><code>function getLatestActivities(){
     $.ajax({
        type: "GET", url: "include/process.php", 
        data:{
           getLatestActivity: "true",
           toUser: "4",
           ignoreMessages:"1",
           dataType: "json"
        },
        success: function(data){
           $.each(data, function (i, elem) {
              alert(data.id);
           });              
        }
     });   
  }
  </code></pre>
  
  <p>The alert prints out the message "undefined", any help would be appreciated thank you.</p>