Reputation: 5271
This is my function
<?php
function checkname($arr, $name) {
foreach (array_slice(func_get_args(), 1) as $name) {
if (strpos($arr, $name) !== false) {
return $name;
}
}
return '';
}
?>
So I could use it this way,
$_val = checkname($arr[$i], 'image1', 'image3', 'image2'........);
however if I make a variable like
$newVal = “image1”,“image3”,“image2”,“stores1”,“stores2”,“stores”,“stores3”,“stores4”,“design1”,“design2”
$_val = checkname($arr[$i], $newVal);
this way doesnt work, wont get any result or $newVal
has to be an array?
Upvotes: 0
Views: 51
Reputation: 1878
Use an array to pass the values to the function:
function checkname($arr, $names) {
foreach ($names as $name) {
if (strpos($arr, $name) !== false) {
return $name;
}
}
return '';
}
print_r(checkname($arr[$i], array('image1', 'image3', 'image2'));
$newVal = array('image1','image3','image2','stores1','stores2','stores','stores3','stores4','design1','design2');
print_r(checkname($arr[$i], $newVal));
Upvotes: 1