Greetings all
I ran into a situation while coding that I needed to delay the execution or initialization of a variable array until needed in a loop. However, because I wanted to make the function reusuable, I also wanted to declare that variable outside of the loop too.
The issue lies within the array's index is dependent on the loops counter. So in essence... I tried to declare the array with index outside of the loop--that obviously didnt work; I tried to comment out the array in the statement I was using for the loop (outside the loop)--that didnt work.
I'm left wondering at this point if it is possible to use an array from outside of a loop that it is necessary to use that loops counter for the index.
Usleep, sleep, pass by reference... are all other methods I have tried that didnt seem to work.
Here's some of the code.
$sql_st[0][0]= "monkey";
$sql_st[0][1]="carrot";
$sql_st[0][2]="dog";
$sql_st[0][3]= "monkey";
$sql_st[0][4]="carrot";
$sql_st[0][5]="dog";
echo $sql_st[0][4];
$values= "INSERT INTO MEDIA (START, END, BEGIN) VALUES ($sql_st[0][$i])";
settype($values,"string");
//echo $values;
echo $a_count;
function test(& $values,$sql_st)
{
$values= "INSERT INTO MEDIA (START, END, BEGIN) VALUES (" . $sql_st[0][$i] . ")";
$a_count=count($sql_st[0]);
For($i=0;$i<$a_count;$i++)
{
echo "This is me " . $i . "<br>";
echo "INSERT INTO MEDIA (START, END, BEGIN) VALUES ('" . $sql_st[0][$i] . "')";
}
}
test($values,$sql_st);
There's a bit more to the code that I am using. It's definitely a logic error; I am hoping there is a method that will make this work. Some of the echoing out are just for tests; in fact, this entire portion of code is a rewrite.
Thanks in advance!
Jason 😕