0
$a = array(000,400,000,500);
    $b = array(300,400,450,500);

    $i=0;
    foreach($b as $k=>$v)
    {
        if($v==$a[$i])
        {
            $b[$k]='000';
        }
        $i++;
    }

    print_r($b);

i want same thing in two dimensional array

$a = Array ( [0] => Array ( [0] => 000000 [1] => 000400 [2] => 000450 ) [1] => Array ( [0] => 000350 [1] => 000400 ) )

$b = array(0=>000350,1=>000400,2=>000450) //pre-defined installment amount values

4
Contributors
4
Replies
27
Views
3 Years
Discussion Span
Last Post by blueguy777
0

I have no idea what you are trying to do here.

You have two 1D arrays, do you want to merge these arrays so they become a 2D array?

0

As the others I've some difficult to understand the result you want to get, to me it seems a compare between A/B arrays, when the values of the correspondent keys are the same, then return 000000, in the other cases return the value of A, unless A is 000000 itself, in that case return the value of B, am I right?

If yes try:

<?php

$a = array(0 => array(0 => '000000', 1 => '000400', 2 => '000450'), 1 => array(0 => '000350', 1 => '000400'));
$b = array(0 => '000350', 1 => '000400', 2 => '000450');

foreach($a as $k => $v)
{
    $i = 0;
    foreach($v as $k2 => $v2)
    {
        if($v2 == $b[$i]) $a[$k][$i] = '000000';
        if($v2 == '000000') $a[$k][$i] = $b[$i];
        $i++;
    }
}

print_r($a);

Outputs:

Array
(
    [0] => Array
        (
            [0] => 000350
            [1] => 000000
            [2] => 000000
        )

    [1] => Array
        (
            [0] => 000000
            [1] => 000000
        )

)

Removing the second IF statement, will return 000000 also for $a[0][0], because it will keep the value of the array A.

Note: I converted the values of the arrays to strings, because as integer will not keep the padding zeros.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.