Skip to content
Advertisement

How to append data obtained from database to array?

I would like to append data(“username”) from database to array(“array1”) and write all items from array. I have marked problematic part of code. If I run this code, I see: What can be wrong?

Output

JavaScript

data_to_array.php

JavaScript

Advertisement

Answer

Try this:

JavaScript

You can also make the for loop neater:

JavaScript

In your original code you were inserting an array with the lement ‘username’ to your $array1
Writing just ['foo'] is the same as array('foo');

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement