lilmer Posted April 19, 2013 Share Posted April 19, 2013 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. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 19, 2013 Share Posted April 19, 2013 you can use array_intersect to find out if an array has ANY values found in another array. $match = array(1,2,3,4); // list of values to match $result = array_intersect($acc_s,$match); if(empty($result)){ echo 'no access'; } else { echo 'access allowed'; } Quote Link to comment Share on other sites More sharing options...
lilmer Posted April 20, 2013 Author Share Posted April 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.