Help with array();


I cannot for the life of me figure out why this doesn’t work and I’m sure it is so simple.


<? include 'mysqlconnect.php'; include 'header.php'; $Employee_Array=array(); function buildEmpArray($NumOfEmps) { for ($i=0; $i<$NumOfEmps; $i++) { $Employee_Array[$i] = "Employee"; } } function echoArray() { $EmpCount=count($Employee_Array); echo "

"; for ($i=0; $i<$EmpCount; $i++) { echo $Employee_Array[$i], "
"; } echo "

"; } [/php] ...form code here..... posts back to itself [php] if (isset($_POST['submit'])) { $NumOfEmps=$_POST['num_of_emps']; $EmpsPerShift=$_POST['emps_per_shift']; $Duration=$_POST['duration']; buildEmpArray($NumOfEmps); echoArray(); } include 'footer.php'; ?>


No matter what value is passed with $NumOfEmps it never adds any values to the $Employee_Array


Might need to change the name of that echoArray function, it could be thinking that you’re just mistaking it for each Array(). Any variable that you’re going to be using outside that function needs to be made global.
function buildEmpArray($NumOfEmps) {
for ($i=0; $i<$NumOfEmps; $i++) {
$Employee_Array[$i] = “Employee”;
return $Employee_Array;

function echoArray($num) {
echo “

for ($j=0; $j<$EmpCount; $j++) {
echo $num[$j]. “
echo “


if (isset($_POST[‘submit’])) {

$BA = buildEmpArray($NumOfEmps);