PHP array combine fieldnames?


#1

Hi, there is an API that I am requesting data from and it is returning the reponse into an array, but like this:

[NAME0] = “MIKE”
[NAME1] = “JOHN”
[NAME2] = “STEVE”

I can get the data into SQL but I have to specify each time like:

[php]
$name = $httpParsedResponseAr[NAME0];
sqlsrv_query($connection, “INSERT INTO Database (Names) VALUES (’$name’)”);
$name = $httpParsedResponseAr[NAME1];
sqlsrv_query($connection, “INSERT INTO Database (Names) VALUES (’$name’)”);
[/php]

But there are hundreds of them. How do I simplify this whole thing, with a Loop or something? As you can tell I am new and inexperienced at this. Any help would be greatly appreciated!

Leo


#2

yep, it would be something like
[php]
foreach($httpParsedResponseAr as $resp) {
sqlsrv_query($connection, “INSERT INTO Database (Names) VALUES (’$resp’)”);
}]/php]