i'm confused, before your example you want to store the hex result in an array, but your example shows you storing the result in a string.
here's how you would store the result in a string.
PHP Code:
<?php
$result = '';
$string = "32451";
$numbers = array('1','2','3','4','5'); // array1 - stores numbers 1-5
foreach ($numbers as $each) {
if (strstr($string, $each)) {
$result .= dechex($each);
}
}
?>