Jump to content

Recommended Posts

Hello, how would I pick an item from these 2 fields randomly, instead of one at a time? For example this picks an item randomly from both $one1 $one2 separately. How can I choose randomly from both of them instead? So that I only have one result at the end instead of 2? Please let me know, thank you very much.

 

<?php 
$one= "<span style='color: rgb(70,0,0)'>test1</span>"; 
$one[3] = "file1.txt"; 
$one1 = preg_grep('/(?:<span)/', $one); 
$one2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT); 
$get1 = $one1[array_rand($one1)]; 
$get2 = $one2[array_rand($one2)]; 
$get3 = file_get_contents($get2); 
echo $get1; 
echo $get3; 
?> 

Thanks both of you. Priti, what does the 1 do here? I dont know how to try it.

($araay,1);

 

 

I also tried these, this returns the file file1.txt on every page load correctly and never shows the text "test1".

 

<?php 
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>"; 
$one[2] = "file1.txt"; 
$two1 = preg_grep('/(?:<span)/', $one); 
$two2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT); 
$rand1 = $two1[array_rand($two1)]; 
$rand2 = $two2[array_rand($two2)]; 
$file = file_get_contents($rand2);
$get = $rand1 + $file;
echo $get;
?> 

 

.....This only brings back the word "Array" on every page load and nothing else. Is there anyway I can grab onto both? Please let me know, thank you very much.

 

<?php 
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>"; 
$one[2] = "file1.txt"; 
$two1 = preg_grep('/(?:<span)/', $one); 
$two2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT); 
$rand1 = $two1[array_rand($two1)]; 
$rand2 = $two2[array_rand($two2)]; 
$file = file_get_contents($rand2);
$get = array_merge($rand1,$file);
echo $get;
?> 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.