Hi, there are two different arrays, a dynamic form. Is it possible to pass both of these arrays in one cycle?
3 answers
If these are two arrays of the same length, you can bypass them like this:
<?php // $_POST['arr1'], $_POST['arr2'] - полученные массивы foreach ($_POST['arr1'] as $key => $arr1_value) { $arr2_value = $_POST['arr2'][$key']; } You can also add a check for the presence of a key in the second array in order to avoid notes.
|
Generally not. But you can, if the arrays are the same length.
Here in 2008 already discussed.
So:
$a=array('123','234','345'); $b=array('a','b','c'); while (list(, $v1) = each($a)) { list(,$v2) = each($b); echo "Value: $v1 = $v2<br />\n"; } Or so:
while ((list(, $v1) = each($a)) && (list(,$v2) = each($b))) { echo "Value: $v1 = $v2<br />\n"; } |