Hi, there are two different arrays, a dynamic form. Is it possible to pass both of these arrays in one cycle?

    3 answers 3

    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.

      array_map allows array_map to array_map several arrays, also use for forms

      • The cool thing is array_map, did not know, thanks! - cyber_bober

      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"; }