1

I have 2 Arrays

$name   = Array ( [1] => Potrait Color Correction [2] => Extraction ) 
$number = Array ( [1] => 060716113223-13555       [2] => 49101220160607-25222 )

I'm trying to print the index 1 of first array with index 1 of 2nd array and similary for index 2

This Is My code For Printing (think it's wrong)

foreach ($name as $abc => $val) {
    foreach ($number as $xyz => $valu) {
        if(!in_array($val, $arr)){
            //echo $val."  ";echo $valu;
            $arr[]=$val;     
        }               
    }
}

Problem is my array number is printing only the first value Is Getting Repeated for both

Potrait Color Correction 060716113223-13555

Extraction 060716113223-13555

im looiking for something like this TO Echo

Potrait Color Correction 060716113223-13555
Extraction 49101220160607-25222
Ben
  • 8,894
  • 7
  • 44
  • 80
Reuben Gomes
  • 878
  • 9
  • 16
  • If the arrays are is same order then you can use something like: array_combine(); – ash__939 Jul 06 '16 at 10:56
  • yea but the thing is i require the data to be printed separately as i will need it to put it into the table to two separate columns – Reuben Gomes Jul 06 '16 at 11:02
  • You can do a foreach loop. The values from the first array will be the key and the values from the second array will be its values. Then you can print it as you like. – ash__939 Jul 06 '16 at 11:13

2 Answers2

1

Use for loop to access multiple array:

for($i=0;$i<count($name);$i++) {
  echo $name[$i]." ".$number[$i]."<br />";
}

Output:

Potrait Color Correction 060716113223-13555

Extraction 49101220160607-25222
Jayesh Chitroda
  • 4,987
  • 13
  • 18
0

Simply use the index from the first and only foreach to reference the second array like this

$name   = Array ( [1] => Potrait Color Correction [2] => Extraction ) 
$number = Array ( [1] => 060716113223-13555       [2] => 49101220160607-25222 )

The code

$arr = [];
foreach ($name as $idx => $val) {
    if(!in_array($val, $arr)){
        echo $val . '  ' . $number[$idx] . '<br>';
        $arr[]=$val;     
    }               
}

Or if this is a CLI script use PHP_EOF instead of <br>

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149