A PHP array crosses it – Stack overflow in Spanish

I have a problem with the board in PHP and it will not be because I do not look at examples of the truth, but I still do not understand their nature, either because I'm used to Java or I can not say why. I give an example:

I believe my board

$ messages = array ();

Well, it's a board, without any problem, an object containing a collection of other objects (items).

If I now have a loop with which fill it board, with the intention of doing so board associative, I would like to do the following:

while ($ row = mysqli_fetch_array ($ result)) {

echo "MESSAGE ID =". $ row['mensaje_id']. "
"; echo "TITLE MESSAGE =". $ row['mensaje_titulo']. "
"; echo "CONTENT OF MESSAGE =". $ row['mensaje_contenido']. "
"; echo "CREATEAT MESSAGE". $ row['mensaje_createAt']. "
"; echo "MESSAGE CREATOR =". $ row['mensaje_creador']. "
"; echo "MESSAGE URL IMG =". $ row['mensaje_url_img']. "
"; echo "LABEL ID =". $ row['etiquetas_ids']. "
"; echo "NAME LABEL =". $ row['etiquetas_nombres']. "
"; echo "------------------
"; // $ tags = explode (& # 39;), $ row['etiquetas_nombres']) $ messages['id'] = $ row['mensaje_id']; $ messages['titulo'] = $ row['mensaje_titulo']; $ messages['contenido'] = $ row['mensaje_contenido']; $ messages['createAt'] = $ row['mensaje_createAt']; $ messages['creador'] = $ row['mensaje_creador']; $ messages['url_img'] = $ row['mensaje_url_img']; }

As you can see, it's a loop while that for each iteration of the $ result I go store its content in my variable $ row, he will have each iteration aboard loaded with different values.

So I say: I will save the iterations I store in $ row by separating them by their attributes(id, title, content, createAt, ..)

Once the loop is completein theory, I must have the variable $ messages loaded with all this data

Well, my next step is to check that the board $ messages so I do that:

foreach ($ messages like $ key) {
echo $ key['id'];
echo $ key['titulo'];
echo $ key['contenido'];
echo $ key['createAt'];
echo $ key['creador'];
echo $ key['url_img'];
}

Apparently PHP NO Allow me, he says Illegal String Offset & # 39; id & # 39; and so with everybody the attributes.

Then I try with the following:

foreach ($ messages like $ key) {
echo $ key;
}

It shows me:

141title message 2content message 22019-04-25 20: 29: 1515cc1fc7ba0c713.37620569.png

C & # 39; is to say, one of the many $ ranks that should have been stored, that's what troubles me, the one that does not store all the data that is in the loop I go attribute. What seems to be that crushing the previous value for each iteration