Jump to content

Recommended Posts

I don't know if this is possible. It sounds like it should be. Hopefully I can explain, but here I go:

I have an array that is combined with varibles that say either 1 or 0 (true or false). What I want to do if possible, is take that array, everytime the arrays value = 1 ($array[0] = 1) show a script. Which will be a while loop also to handle some mysql arrays.  My main goal is so I don't have to copy paste the while script over and over. Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/
Share on other sites

To me it sounds like your having a problem cycling through your array.  Is that your main issue?  If so try something like:

 

$arrayCount = count($array);
$X = 0;
while($X <= $arrayCount){
     
     if($array[$X] == 1){
          //Conduct  your test for 1 or 0 here and run your while loop here if satisfied.
     }
     $countX++;

}

Link to comment
https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424112
Share on other sites

There are a number of ways in PHP to loop through arrays "for","foreach","while" come to mind.

 

"for" example:

<?php
for ($i = 0;$i < count($array);$i++) {
//
//  do the work
//
}
?>

 

"foreach" example:

<?php
foreach ($array as $ind => $val) {
//
//  do the work
//
}
?>

 

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424132
Share on other sites

  • 1 month later...
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.