how to apply condition for print values ??of an array
-
how to apply condition for print values ??of 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, the big problem down was that each new access to posts, or refresh the kapok, a new number / value was generated, and this could not happen, I needed to write permanently on those values ??in the posts and below the solution but can not apply in arrays!
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 to apply condition with arrays:
function shuflenames() { global $post; $mixnames = get_post_meta( $post->ID, 'my_custom_meta', true ); if ( '' == $mixnames) { $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); $rand_keys = array_rand($input, 2); update_post_meta( $post->ID, 'my_custom_meta', $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.
- The topic ‘how to apply condition for print values ??of an array’ is closed to new replies.