Jump to content

Loop in statment


mraza

Recommended Posts

Hi , i have this code and i am trying to change the variable untill the loop run but can't figure out how, means in function ($var1, $vart2) when the next loop come it use the value $var3 and $var4 and in next use again $var1 and $var2 till the for loop finish it will continue this way, here the code:

$var1 = $_POST['note1'];
$var2 = $_POST['com1'];
$var3 = $_POST['note2'];
$var4 = $_POST['com2'];

for($i= 0;$i < sizeof($somevar);$i++)
{
//my other statements

function ($var1, $vart2);
}

i tried this way but it will give me the result only of $var3 and $var4 :

$var1 = $_POST['note1'];
$var2 = $_POST['com1'];
$var3 = $_POST['note2'];
$var4 = $_POST['com2'];

$note = array(1=>"$var1", "$var3 " );
$com = array(1=>"$var2", "$var4 " );
$random = rand(1,2);

$var1 = $note["$random"];
$var2 = $com["$random"];

for($i= 0;$i < sizeof($somevar);$i++)
{
//my other statements

function ($var1, $vart2);
}

Please any help

Link to comment
Share on other sites

Thanks sir it worked but now the problem is they are giving both same result, means if i write something in file with $_POST['note1'] it will also be written with $_POST['note2'] and then move to next and same again whatever is in $_POST['note1'] it will be written by $_POST['note2'], if you see there $content, it is being written twice, what i want is as in my first post i used rand() so when the loop run again it will change the value of $var1 and $var2 .here i tried the code maybe something i am missing for sure :(:

$arr = Array( $_POST['note1'],
                  $_POST['com1'],
                  $_POST['note2'],
                  $_POST['com2']
              );

for($a= 0;$a< sizeof($somevar);$a++)
{
//my other statments for content

for($i = 0, $c = count($arr);$i < $c;$i+=2)
{
somefunction($content,$arr[$i], $arr[$i+1]);
}
}

Thanks for help

 

Link to comment
Share on other sites

sorry for double post i could not edit about if you notice in somefunction($content,$arr[$i], $arr[$i+1]); i have $content, so when the loop runs second time it prints $content again, i wants to move it to next as i am using in script so only when the function run next time it change the value of $var1 and $var2 in somefunction ($content, $var1, $var2);

Link to comment
Share on other sites

sorry sir for confusion i will try to explain here is the original code, codes file are large so i am posting what is important:

$user = $_POST['user'];
$pass = $_POST['pass'];
$user2= $_POST['user2'];
$pass2 = $_POST['pass2'];

for($i= 0;$i < sizeof($links);$i++)
{
echo "On Page". $body . "<br />" ;
$curl = $turl[0].$links[$i]["href"];
$lcontent = getcontent($curl);
$content = getthreadcontent($lcontent);
getting($title,$content,$web,$user,$pass);
}

here what i want is when next time loop run it will change the value of $user and $pass to $user2 and $pass2, so basically what i am trying to do is post with other username next content.

Link to comment
Share on other sites

What about something like this?

 

$arr = Array(
Array(
	$_POST['note1'],
	$_POST['com1']
),
Array(
	$_POST['note2'],
	$_POST['com2']
)
);

for($i = 0, $c = count($arr);$i < $c;$i++)
{
$curl = $turl[0].$links[$i]["href"];
$lcontent = getcontent($curl);
$content = getthreadcontent($lcontent);
something($content, $arr[$i][0], $arr[$i][1]);
}

 

As long as you're excluding content it's hard for me to understand exactly what you're trying to do.

Link to comment
Share on other sites

thanks sir for you quick support much appreciated,  i want to run this loop for($i= 0;$i < sizeof($links);$i++)  as you can see in my previous post so until $links will finish loop will run but $user and $pass will change randomly only to that both variables i mention above when next time loop runs.

Link to comment
Share on other sites

You want to loop through the entire $links array and randomly choose the user/pass combination? Then do something like this:

 

$arr = Array(
Array(
	$_POST['note1'],
	$_POST['com1']
),
Array(
	$_POST['note2'],
	$_POST['com2']
)
);

for($i = 0, $c = count($links);$i < $c;$i++)
{
$curl = $turl[0].$links[$i]["href"];
$lcontent = getcontent($curl);
$content = getthreadcontent($lcontent);
$rand = array_rand($arr);
something($content, $arr[$rand][0], $arr[$rand][1]);
}

Link to comment
Share on other sites

That won't work. It'll give output like: first iteration: name1, name1; second iteration name2, name2; third name1, name1, etc.. I think you mean something like this:

 

$x = 1;
for($i= 0;$i < 4;$i++) {
     $x = ($x < 4) ? $x : ($x = 1);
     someFunction(${'var'.$x}, ${'var'.++$x});
     $x++;
}

 

If you're going to do it that way might as well put $x inside the for()'s parameters to make it cleaner (like below). But I was under the impression that the OP wanted it to be random.

 

for($i= 0, $x = 1;$i < sizeof($somevar);$i++, $x = (++$x < 4) ? $x : 1)
    someFunction(${'var'.$x}, ${'var'.++$x});

Link to comment
Share on other sites

Thanks sir you are right the last one too works, one last question regarding to this what if i have more array like (I am using the last script by your sir Alex with array_rand):

$user = $_POST['user'];
$pass = $_POST['pass'];
$user2= $_POST['user2'];
$pass2 = $_POST['pass2'];
$user3 = $_POST['user3'];
$pass3 = $_POST['pass3'];
$user4= $_POST['user4'];
$pass4 = $_POST['pass4'];
//shoud i do this
$arr = Array( Array($tuser1,
			$tpass1),
		  Array($tuser2,
			$tpass2 ),
		  Array($tuser3,
			$tpass3),
		  Array($tuser4,
				$tpass4 )
		);

THANKS ALOTSSSS

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.