I am using one of the jquery ui autocomplete functions and have a requirement to create a php array populated in a foreach loop containing results from a PDO SELECT query.
The resultant array should look like this:
Array(
"result1"=>"result1",
"result2"=>"result2",
"result3"=>"result3",
"result4"=>"result4"
"remaining results"=>"remaining results"
);
I tried this:
echo '$items = array(';
foreach($resulttags as $tag_rows)
{
$tags_display = $tag_rows['tag'];
echo '"' . $tags_display . '"=>"' . $tags_display . '",';
}
echo ");";
That echos out the array on the page but it does not work. I also tried this:
$items = array();
foreach($resulttags as $tag_rows)
{
$results['"' . $tag_rows['tag'] . '"'] = '"' . $tag_rows['tag'] . '"';
}
But this results in square brackets around the array keys, and does not seem to want to work with the autocomplete. I am assuming the downvotes are b'c I did not show what I had tried already, I posted the question on my iPhone, and am now back to my laptop.
Im thinking this shouldnt be too hard but I have tried a number of approaches that have not worked. Any suggestions? These arrays Always give me fits, have not gotten my head around them yet.
$var[] = ...
.