php - Array Echo Together Each Value Together -
this question has answer here:
i have 2 arrays
$name = array ( [1] => potrait color correction [2] => extraction ) $number = array ( [1] => 060716113223-13555 [2] => 49101220160607-25222 )
i'm trying print index 1 of first array index 1 of 2nd array , similary index 2
this code printing (think it's wrong)
foreach ($name $abc => $val) { foreach ($number $xyz => $valu) { if(!in_array($val, $arr)){ //echo $val." ";echo $valu; $arr[]=$val; } } }
problem array number printing first value getting repeated both
potrait color correction 060716113223-13555
extraction 060716113223-13555
im looiking echo
potrait color correction 060716113223-13555 extraction 49101220160607-25222
simply use index first , foreach
reference second array this
$name = array ( [1] => potrait color correction [2] => extraction ) $number = array ( [1] => 060716113223-13555 [2] => 49101220160607-25222 )
the code
$arr = []; foreach ($name $idx => $val) { if(!in_array($val, $arr)){ echo $val . ' ' . $number[$idx] . '<br>'; $arr[]=$val; } }
or if cli script use php_eof
instead of <br>
Comments
Post a Comment