Function that makes the direct $foo[array_rand($foo)]

Asked

Viewed 43 times

-2

There is a native PHP function that does this without using array_rand in the array key?

Although it is working well and is a simple stretch, it follows a simplified example of doubt:

//Declarando um Array com um Array dentro
$array_pai = Array ( 
         [0] => Array ( 
            [bar] => ":)"
            [altbar] => "=]"
          )
         [1] => Array ( 
            [bar] => ":("
            [altbar] => "=["
          )
         [2] => Array ( 
            [bar] => ":p"
            [altbar] => "=p"
          )
       );

//Pegando o Array filho aleatorio
$array_filho= $array_pai[array_rand($array_pai)];
print_r($array_filho);

Upshot:

Array ( 
   [bar] => ":)"
   [altbar] => "=]"
)

There is a Native Function that does this process?

  • Friend, I don’t understand anything. Don’t just put code, you need to explain what you need. If many posts giant texts and little code you posted too much code but did not explain anything. Please explain little more there for us.

  • I didn’t understand the question or the expected exit.

  • Epa, I swear I didn’t understand anything about anything. You can explain better what you want to get ?

  • I edited the question! Thanks for the touch.

  • You select a random key from the parent array and play it in another array?

  • 1

    In other words, make an array_rand by returning the result instead of the key.

Show 1 more comment

1 answer

3


Browser other questions tagged

You are not signed in. Login or sign up in order to post.