Passing array variable in shell_exec

Hi all,

i wrote a php script in which i passed some values in the array variable using a for loop.

I have to pass this array values to a shell script using shell_exec()

<?php
while($row = mysql_fetch_assoc($ansid))
{
//$row = mysql_fetch_assoc($ansid);
$aid[$i] = $row['id']; 
echo $aid[$i];
$i = $i + 1;
}
shell_exec("sh Ans.sh '$aid[$i]'");
?>

but all the array values are not passed to my Ans.sh file.

Please help me!

Thanks

Probably because of incorrect variable scope. See PHP: Variable scope. You are using $aid outside the loop.

1 Like

Thanks.. It is resolved for me..