Jump to content

Putting 'foreach' into an array


Jragon

Recommended Posts

Hey guys,

 

I was wondering how i could put a foreach statement into varible or array.

 

My code:

<?php

function permute($array,$positions,&$perms,$previous = null) {
  if($positions > 0) {
if(!isset($previous)) {
  $previous = array();
}

    foreach($array as $element) {
  $tempPrevious = $previous;
  $tempPrevious[] = $element;
  permute($array,$positions-1,$perms,$tempPrevious);
}
  } else {
    $perms[] = $previous;
  }
}

$perms = array();
$letters = array('a','b','c','d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'x');
$numofletters = 3;

permute($letters, $numofletters, $perms);

foreach($perms as $key => $row){
    foreach($row as $letter){
        echo $letter;
    }
    echo '<br />';
}
?>

 

It creates random letter arrangements and i want to put those letters in to a array so that it would look like this:

$1 = array('aaa', 'aab' ECT)

 

and then i want to put it in to a while loop and MD5 it so it will look somthing like this:

while($letterarray){
    echo $letterarray;
    echo md5($letterarry);
}

 

so in the end it will out put somthing like this:

word
md5ed word
word
md5ed word
word
md5ed word
word
md5ed word
word
md5ed word
word
md5ed word
word
md5ed word
word
md5ed word

 

Any help would be much appreciated

 

Thanks

 

Jraogn

 

Link to comment
https://forums.phpfreaks.com/topic/208554-putting-foreach-into-an-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.