Home > Elgg Only, Logic, open source products, PHP, Tricks > How to use two conditions in foreach loop

How to use two conditions in foreach loop

How to use two conditions in foreach loop :

Ans :

We can’t put two conditions in foreach loop.So, we should use only one condition & also use some trick to supprot the two condition’s.

1.Use one condition in foreach loop ex : foreach($array as $values) normally.

2.Then use increment operator to support the second array loop.

Example :

$i=0;
foreach ($label_ as $labels) {
add_submenu_item(elgg_echo($labels), $url_[$i]);
$i++;
}

  • Here,i should use two array values in foreach loop.For that, first i took one in foreach loop & directly put another as array using increment operator.
  • Here ,both $labels & $url_ have same count….So the increment support me nicely…Even if the count varies we can achieve it through using if condition.
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: