Sublime Forum

Pre-formatted snippet foreach

#1

I am following a PHP course and the instruction calls for

foreach ($array as $value)

but ST3 keeps defaulting to

foreach ($array as $key => $value)

giving me an error

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testsite.test\CMS\admin\includes\view_all_posts.php on line 6 ""; ""; ""; "";

Is there a way to get around this please?

0 Likes

#2

I am afraid that your $array is not an array. foreach ($array as $key => $value) is fine but just $key is an unused variable.

0 Likes

#3

Not sure what you mean

Blockquote your $array is not an array .

0 Likes

#4

such as

$array = ''; // not an array
foreach ($array as $key => $value) { ... }
// Warning: Invalid argument supplied for foreach() in...
0 Likes