tags:

views:

27

answers:

1

Below php code I have selected "Neo" so Neo should not pick in the random selected. And another 2 value should print.

  <?php
    $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
    $rand_keys = array_rand($input, 2);
    echo $input[$rand_keys[0]] . "\n";
    echo $input[$rand_keys[1]] . "\n";
    ?>

And my array is Multi-dimentionnal array here is sample

array(1) { ["data"]=>  array(301) { [0]=>  array(2) { ["name"]=>  string(10) "Some Name" ["id"]=>  string(9) "5000213929" }
A: 

How do you know what "has been selected"? Is it in a variable? You will need to know that in order to unset the value from the array using array_search

unset($input[array_search('Neo', $input)]);
$rand_keys = array_rand($input, 2);

Which should unset Neo thus making it not an option to be used in the randomization. There are probably better ways to do this, but this is one way. And of course, if you do have a way to determine if Neo was selected, you would use that variable in place of 'Neo'.

Brad F Jacobs
I am getting NULL since my array is 2 dimensional array
Elankeeran