Help:php array mix(like cross of math sets)

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

2 replies · 476 views · started 14 years ago · 1 min read

3 participants
Sifat3d Developer · 66 posts #1

HI, i need help with this.

<?php
$main_array	=array('x','y');
$some_array	=array('a','b');

How can i get

$new_array=('ax','ay','bx','by');

Someone please help me, the original main_array and some_array contain too much(50 each)data and they change hourly, So its impossible for me to do it manually, i need it done using php and i will use the new_array in a simple str_replace. All help will be appreciated.

Fake hack any website,even coding-talk for some clean FUN!!! Try: fake hacking website Mig33 Software for pc: Mig33 for PC mobile games and software download

something else Fellow · 2,296 posts #2
$main_array = array('x','y');
$some_array = array('a','b');
$new_array = array();
$t = 0;
for ($i = 0; $i <= count($some_array)-1; $i++)
{
   for ($a = 0; $a <= count($main_array)-1; $a++)
   {
        $new_array[$t] =  $some_array[$i].$main_array[$a];
        $t++;
   }
}
GumSlone Administrator Principal · 1,690 posts #3

actually the same code as posted by something else

$main_array = array('x','y'); 
$some_array = array('a','b'); 

for ($i = 0; $i < count($some_array); $i++) 
{
	for ($k = 0; $k < count($main_array); $k++) 
	{
		$new_array[] =  $some_array[$i].$main_array[$k]; 
	}
}
print_r($new_array);

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close