Jump to content

Recommended Posts

Hy there.. i need to make a loop that will run trough an array and if the loop is not over.. the array parsing should go on. But i'm stuck and i need some help.

Here is a snippet if anyone is kind enough to take a look.

Btw... i'm no php guru, still learning, Thanks!

function generate($var)
{
$num = array("0","9","7","5","3","1","1","6","4","2");

$afd['zorg'] = $var;
$afd['p'] = $afd['zorg']{11};
$afd['nct'] = $afd['zorg']{12};
$afd['nrv'] = $afd['zorg']{0};
$afd['mid'] = $afd['zorg']{1}.$afd['zorg']{2}.$afd['zorg']{3}.$afd['zorg']{4}.$afd['zorg']{5}.$afd['zorg']{6}.$afd['zorg']{7}.$afd['zorg']{8}.$afd['zorg']{9}.$afd['zorg']{10};

$key = $afd['nct'];
$a = $afd['p'];

for ($i=0;$i<=9;$i++)
	{
	$mode = next($num);	

	echo "<br>****Num = :$mode<br>";	

	if($mode==$key)
	{
		echo "<br>*Match Found num:$mode - key:$key";
			if ($mode == 2)
			{
				$mode = reset($num);

				$a = $a + 1;					
			}	
		break(1);
	}
}

for($i=0;$i<10;$i++)
	{

	echo "<br>*Magic number :".$afd['nrv'].$afd['mid'].$a.$mode."*<br>";

	$mode = next($num);
	$a = $a+1;

	if($a == 10)
	{
		$a = 0;
	}
}
}

 

It is hard for me to explain the problem, but.. i will try to...

If i start with this number: 2555555555551

the output will be :

2555555555551

2555555555561

2555555555576

2555555555584

2555555555592

255555555550

255555555551

255555555552

255555555553

255555555554

My problem is that i don't know how to make the array go over again even if it reached the end.

 

Thanks for your patiance!!!

Link to comment
https://forums.phpfreaks.com/topic/165145-array-script/
Share on other sites

$loops = 2;
for ($i = 0; $i < $loops; ++$i) {
    $sizeOf = sizeof($array);
    for ($j = 0; $j < $sizeOf; ++$j) {
        // ..logic..
    }
}

 

increase $loops if you need to loop over more or use some algorithm to decide how many times it needs to loop over the array

Link to comment
https://forums.phpfreaks.com/topic/165145-array-script/#findComment-870862
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.