I have 2 conditions, first one is foreach ($list as $p) PHP: and secode one is foreach ($list2 as $p2) PHP: now i want to make like this, foreach ($p+$p2 as $total) PHP: how can I make this ? please help
I dont know foreach, but for IF, do something like this: <?php $p = 1; $p2 = 2; $total = 3; if($p+p2 == $total){ do something } else { Do something else } ?> Code (markup):
<?php $list = [1,2,3,4,5,6]; $list2 = [1,2,3,4,5,6]; $count = count($list); for ($i = 0; $i < $count; $i++) { echo $total = $list[$i] + $list2[$i]; } ?> PHP: Assumes both arrays are of the same length
Dear see this, $first = array('red','orange','yellow','green','lime','maroon','white','black'); $second = array('first','second','third','4th','5th','6th','7th','8th'); foreach ($first AND $second as $third){ echo $third; } PHP: I Want result like this red,orange,yellow,green,lime,maroon,white,black,first,second,third,4th,5th,6th,7th,8th Code (markup): How can I combine this ?
You just want to output both arrays after eachother? That doesn't involve any kind of plus signs... echo $list = join(',',array_merge($list,$list2)); Code (markup):
Bro one more question, If have this $first = array('red','orange','yellow','green','lime','maroon','white','black'); foreach ($first as $list) $second = array('first','second','third','4th','5th','6th','7th','8th'); foreach ($second as $list2) PHP: Now what should I do ? foreach ($list AND $list2 as $last) PHP:
uhm... you just do echo $last = join(',',array_merge($first,$seond)); PHP: No need for a loop, or reassigning the arrays.