\$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

## All 4 Replies

http://webcheatsheet.com/PHP/multidimensional_arrays.php

I'm actually going to read through that article myself and see if I can grasp it, looks easy enough. Sorry I couldn't help more.

Michael

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?

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.

thanks alot cereal, you have solved my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.