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
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
Share on other sites

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.