Jump to content

Random array values


lilmer

Recommended Posts

I've got a 

foreach ($acct as $val){
                       
   $acc_s = explode(',',$val["access_type"]);
   
}

The value of ACC will  Array from every foreach

 
var_dump($acc_s);

Output:

array(1) { [0]=> string(1) "1" }

array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }

array(2) { [0]=> string(1) "3" [1]=> string(1) "4" }

array(1) { [0]=> string(1) "3" }

My question is, how do I make a condition if the value of the "explode" element have 1 or 2 or 3 or 4.

 

I'd try.



for($i=0;$i<count($acc_s);$i++){
   $out_acc = $acc_s[$i];
}

But it won't give me the right output to what I need.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/277134-random-array-values/
Share on other sites

This idea is working 

for($i=0;$i<count($acc_s);$i++){
$out_acc = $acc_s[$i];
}

but when the array is count is more than one It loops data by the number of count. So when I

 for($i=0;$i<count($acc_s);$i++){

         if($acc_s[$i] == 1){                        
               echo '<li>One</li>';                           
          } 
         if($acc_s[$i] == 2){                        
               echo '<li>Two</li>';                           
          }   
 }

if the number of count is more than one it print the details as of the number of loop. But I don't want like that. And when I make a variable inside the for loop the print it out outside it only get the last value of the loop. Can you give any idea about how I'm going to get the data of an array.

Link to comment
https://forums.phpfreaks.com/topic/277134-random-array-values/#findComment-1425897
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.