Jump to content

Recommended Posts

hi all ,i want to build something like that:

 

$try[] = array( "1", "2", "3");

$try[] = array( "A", "B", "C");

 

then i want to shffle the first array , so it can be 1,2,3 or ,3,1,2 or 2,1,3 ,any combination possible.

 

then i want to have a form so i can submit the result like that

 

if i see the first array is 1,3,2 then i need to type in my input field  ACB

 

and the answer i get is correct ,if the my input is wrong then i get wrong answer .

 

so :

 

1,2,3 = a,b,c

3,1,2 = c,a,b

2,3,1 = b,c,1

 

one more thing , a is not equal to 1 ,a is equal to the possition of 1 ,so it can be 1,2,3 for the first array and g,w,r for the second array!

 

 

my quastion is how im doing something like that , how im tellin the first array that 1 is equal to the position of a and 2 is equal to the position of b .....

and do it in the right way.

 

thanx

Link to comment
https://forums.phpfreaks.com/topic/185338-correct-order-of-array-help/
Share on other sites

Simpler to have 1 array rather than a multi-dimensional array i.e

<?php	
$array = range('A','C');
$keys  = array_keys($array);
shuffle($keys);
// display the shuffled array keys
print_r($keys);

// use the keys to restore the string
for($x = 0; $x < count($keys); $x++) {
print $array[$keys[$x]];
}
?>

thanks bowett ,i didnt know that i can get the array like that :)

 

how im doing that :

 

if the array is like that:

 

array( 1,2,3,4,2,1,4,6,4,2,1,3)

 

can i print the position of number one?

 

so the output will be

array 0 , 5, 10 - this is the position of 1 in the array!

 

thanx

what is the way i need to do it?

 

i want to have my array like this

 

$array[] = array (1,2,3,4)

 

$array[] = array (a,b,k,g)

 

i want to have a form to ask me to input the result in order

the first array will be in shuffle on every refresh of the page!

 

so if i enter my page

 

and the display will show me 2,1,4,3

then i need to type in the form field  b,a,g,k

 

and when i press on submit ,i get back answer if my input was correct!

if didnt input it in the right order ,then i get nagative answer!

 

thanx

 

$array[] = array (1,2,3,4) <==== shuffled

 

$array[] = array (a,b,k,g)

 

 

im entering the page and i get this sequence

 

2,1,4,3

 

and i get a question ,what is equal to 1,3

 

my answer needs to be b,g

 

i need it in a form !

 

thanks

I hope I got you right this is what I came up with

 

<?php
$array1 = array(2,1,4,3);

$array2 = array('a','b','c','g');

$array3 = array();

foreach ($array1 as $key) {
    array_push($array3,$array2[$key-1]);
}

print_r($array3);
?>

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.