Site Bugs
Posted in
5987
7:28 am, May 22, 2022
Invalid argument supplied for foreach()
Fix for
Warning: Invalid argument supplied for foreach() in /var/www/html/pages/seo-meta-tag-search.page.php on line 204
As this is just a warning, i may not have noticed it originally, but as i have all warnings and errors shown now, it is appearing, probably trying to loop through something that is not declared or blank.
https://kruxor.com/seo-meta-tag-search/
Fixed: This was due to looping through an array that was not set.
PHP - Original Code
foreach($kw_latest_json_array as $kw_item) {
$kw_item_title = $kw_item['title'];
$kw_page_url = $kw_item['page_url'];
$kw_page_url_enc = urlencode($kw_page_url);
$kw_group .= "<a href='?import_url=$kw_page_url_enc' class='list-group-item list-group-item-action' title='$kw_item_title'>$kw_item_title</a>";
}
PHP - Check that the array isset
check if its an array, you could probably use isset here as well
if(is_array($kw_latest_json_array)) {
foreach($kw_latest_json_array as $kw_item) {
$kw_item_title = $kw_item['title'];
$kw_page_url = $kw_item['page_url'];
$kw_page_url_enc = urlencode($kw_page_url);
$kw_group .= "<a href='?import_url=$kw_page_url_enc' class='list-group-item list-group-item-action' title='$kw_item_title'>$kw_item_title</a>";
}
}
View Statistics
This Week
113
This Month
524
This Year
2104
Add Comment
Other Items in Site Bugs
Invalid argument supplied for foreach()
Warning: file_put_contents(/var/www/html/bundle/responsive-viewport-meta-tag-responsive-meta-tag/index.php): failed to open stream: Permission denied in /var/www/html/pages/update.page.php on line 167
Warning: Undefined variable $class_single_hero in /var/www/html/pages/section.page.php on line 177
Search Duplicating Bugs
Related Search Terms
Other Categories in Code
alpine js apps c css factorio font awesome images linux quick modals sqlite site bugs site updates slick slider sliders testing windows apps apache api apps asp bat bootstrap bootstrap templates charts cookies core css css filters css grid design elements docker domains emoji fancybox fonts foundation framework gimp git html icons ideas image formatting images javascript javascript functions jquery js linux mac misc modals mysql nginx node php php errors php function php functions php simple html dom pi400 python react regex sections simple_html_dom simplepie php site bugs site documentation slick slider sql sqlite ssh sublime svg svg css templates tools virtual box vscode vue webdev windows windows 11 windows commands wordpress