I have a small function to check an array for invalid characters. Everything works as expected, except that if I try to echo a value of the second array it doesn't output anything.
The echo of $arrTwo within the function works correctly (if you have an invalid string in $arrOne, $arrTwo will be given a value equal to the key of the invalid string.
This is my code:
<?php
global $formComplete;
global $i;
global $arrayLength;
function checkFieldAlphaNum($arrOne, $arrTwo){
$arrTwo = array();
$arrayLength = count($arrOne);
for ($i = 0; $i < $arrayLength; $i++){
if($arrOne[$i] != "" && !preg_match("/[^a-zA-Z0-9\.\-\ß\ä\Ä\ü\Ü\ö\Ö ]+$/s",$arrOne[$i])){
$formComplete = TRUE;
} else {
$arrTwo[$i] = $i;
$formComplete = FALSE;
echo "arrayName at[" . $i . "] is: [" .$arrTwo[$i] . "]<br>\n";
}
}
return $arrTwo;
}
$testTxtArr = array($_POST['testTxt1'], $_POST['testTxt2'], $_POST['testTxt3']);
$testTxtArr2 = array();
checkFieldAlphaNum($testTxtArr, $testTxtArr2);
echo $testTxtArr2['0'];
?>
<html>
<head>
<body>
<form method="post" action="<?php $PHP_SELF ?>">
<?php if($testTxtArr2[0] != ""){ echo "Please complete";} ?><input type="text" name="testTxt1"><br>
<?php if($formComplete == FALSE && $testTxtArr2[1] != ""){ echo "Please complete";} ?><input type="text" name="testTxt2"><br>
<?php if($formComplete == FALSE && $testTxtArr2[2] != ""){ echo "Please complete";} ?><input type="text" name="testTxt3"><br>
<input type="submit" name="submit">
</form>
</body>
</head>
</html>