I am creating a sitemap using XML. When I try to put multiple values to array, I am getting undefined index for the second variable.
Sample code below.
How I gather the results:
$tempArray = array();
switch ($type)
{
case "v":
$dbResult = $db->get_dbResult("Select title,id,vdate from " . DB_PREFIX . "tpV order by id desc " . this_offset($getFirstK));
if ($dbResult)
{
foreach($dbResult as $pResult)
{
$tempArray[]['loc'] = convert_to_URL($pResult->id, $pResult->title);
$tempArray[]['vdate'] = $pResult->vdate;
}
}
break;
How I print the result.
array_filter($tempArray = array_map("unserialize", array_unique(array_map("serialize", $tempArray))));
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($tempArray as $tVars)
{
echo '<url>
<loc>
'.$tVars["loc"].'
</loc>
<lastmod>'.$tVars["vdate"].'</lastmod>
<changefreq>weekly</changefreq>
</url>';
}
echo '</urlset>';
I am getting undefined index error for $tempArray[]['vdate']. Is there anything am I missing?
var_dumpyour$tempArraybefore the foreach just to make sure you're having everything right.