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
3
  • If the arrays are is same order then you can use something like: array_combine(); Commented Jul 6, 2016 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 Commented Jul 6, 2016 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. Commented Jul 6, 2016 at 11:13

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.