how to apply a print condition in an array?
-
hello staff www.ads-software.com
I need help from you again,this function shuffle numbers,
function gen_num()
{
$caracteres = “012345678910111213141516171819”;
$mistura = substr(str_shuffle($caracteres),0,15);
print $mistura;I needed a condition to print or not the numbers at the posts, and the @leglesslizard User helped me. It works perfectly,
function gen_num()
{
global $post;
$mistura = get_post_meta( $post->ID, ‘my_custom_meta’, true );if ( ” == $mistura ) {
$caracteres = “012345678910111213141516171819”;
$mistura = substr(str_shuffle($caracteres),0,10);
update_post_meta( $post->ID, ‘my_custom_meta’, $mistura );
}print $mistura;
}I am now trying to make arrays and I can not!
function shuflenames()
{
$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”;my failed attempt:
function shuflenames()
{
global $post;
$input = get_post_meta( $post->ID, ‘names’, true );
if ( ” == $input ) {
$input = array(“Neo”, “Morpheus”, “Trinity”, “Cypher”, “Tank”);
$rand_keys = array_rand($input, 2);
update_post_meta( $post->ID, ‘names’, $input );
}
echo $input[$rand_keys[0]] . “\n”;
echo $input[$rand_keys[1]] . “\n”;
}Thanks to all, Best Regards.
- The topic ‘how to apply a print condition in an array?’ is closed to new replies.