I use this PHP function to delete some array elements.
function deleteEx ($ind, $kl) {
global $exs;
foreach ( $exs as $key => $examples )
if ( $examples['KL'] == $kl && $examples['id'] == $ind)
unset( $exs[$key] );
}
and I have 2 different functions that calls it during the computation: 1st one is this:
function deleteSub ($editing) {
global $subs, $exs;
$kl= $_POST['kl'];
foreach ( $subs as $key => $subject )
if ( $subject['knowledgeLevel'] == $kl )
unset( $subs[$key] );
if ($editing == 0) {
for ( $i=1; $i <= count($exs); $i++)
deleteEx($i, $kl);
header("refresh:0;url=backdoor.php");
exit;
}
}
2nd one is this:
function editSub () {
$kl= $_POST['kl'];
for ($i= 1; $i<= $_POST['nofexamples']; $i++) {
if (strcmp ($_POST['oldex'.$i], $_POST['example'.$i]) != 0)
deleteEx($i, $kl);
}
deleteSub (1);
}
Calling the function deleteEx within the first function everything works just fine and the result is the expected one. Calling the funcion deleteEx within the second function I get the warning: Invalid argument supplied for foreach() and the results are not what I expected. Any idea of how eliminate the warning? (I guess that's the reason why the function doesn't work fine).