• 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;
    $mixnames = get_post_meta( $post->ID, 'description', true );
    if ( '' == $mixnames) {
    $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
    $rand_keys = array_rand($input, 2);
    update_post_meta( $post->ID, 'description', $mixnames );
    }
    echo $input[$rand_keys[0]] . "\n";
    echo $input[$rand_keys[1]] . "\n";
    }

    but the words change as the condition does not exist. every new access words are changed, they are not actually written in the posts

    Thanks to all, Best Regards.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘how to apply condition for imprmir values ??of an array’ is closed to new replies.