How would I write a for loop within a for loop and get this result?

Bruce Gust
Bruce Gust used Ask the Experts™
on
Here's the tongue twister:

I'm doing a for loop and I get this result:

Florida
Louisiana
Texas
Kentucky

What I need to do is go through that for loop and WITHIN that same cycle do something like this:

First, here's my starting point:

foreach($page_display as $page)
{
//normal listing of results like what you see
}

Now, here's what I need to do:

foreach($page_display as $page)
{
   foreach($page_display as $page)
   {
   if($current_state <> $page['state']
      {
       //here I need to create a list of every state EXCEPT the one, so, in this scenario, I need four different recordsets:
       #1
       Louisiana
       Texas
       Kentucky
       #2
        Florida
        Texas
        Kentucky
       #3
       Florida
       Louisiana
       Kentucky
      #4
      Florida
      Louisiana
      Texas
      }
   }
}

How would I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Year 2008
Top Expert 2008
Commented:
One foreach should suffice
$states = Array('Florida','Louisiana','Texas','Kentucky');

foreach($states as $page)
{
	# $states is an array with the complete list of states
	# array_diff returns all the items in $states that are in Array($page).
	$result = array_diff($states, Array($page));
	print_r($result);
}

Open in new window


If you want an array as the result, try:
$states = Array('Florida','Louisiana','Texas','Kentucky');
$result=Array();
foreach($states as $page)
{
	$result[] = array_diff($states, Array($page));
	
}
print_r($result);

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial