Frage

This is quite a novice question - I've looked at similar solutions to similar problems on here and around the internet however I can't seem to find what the problem is with this one.

I'm playing with PHP and writing a bit of code that pulls all of the mailing data out of an API. However I noticed that load times were very very slow and that was because for each mail's contents I was doing a separate query. I've since figured out how to pull what I'm looking for in one go however I'm having trouble adding the data thats returned to my 2D array that i'm storing the data in before its output.

Here is my array below;

$mailMessage = array(
               array(
        'mailNumber' => $mailCount,
        'mailID' => $mailID,
        'mailDate' => $mailDate,
        'mailSender' => $mailSender,
        'mailSenderName' => null,
        'mailMsg' => null
        ));

And here is how I'm trying to update said array;

    foreach ($mailMessage as &$row){
    if($row['mailID'] == $getMailID){
        $row['mailMsg'] = $body;
    break;
    }
}

So I'm checking if the mailID is the same as the one that i'm currently looking at, then if it is i'm trying to update the mailMsg part of the array on that line to be $body. I've checked the

This however is not working. No PHP error messages are flagging up - (Some times this is worse!) and i'm pretty much hitting my head off of a brick wall.

Thanks for reading & for your time,

Jamie

War es hilfreich?

Lösung

Is there a reason you're using a multidimensional array instead of just an associative? You're not iterating over any indexes because there aren't any present within the aggregated array format. The correct format should be :

Multidimension :

$mailMessage = array(
    0 => array(
        'mailNumber' => $mailCount,
        'mailID' => $mailID,
        'mailDate' => $mailDate,
        'mailSender' => $mailSender,
        'mailSenderName' => null,
        'mailMsg' => null
    )
);

Associative :

$mailMessage = array(
    'mailNumber' => $mailCount,
    'mailID' => $mailID,
    'mailDate' => $mailDate,
    'mailSender' => $mailSender,
    'mailSenderName' => null,
    'mailMsg' => null
);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top