Array in Array help needed "RESOLVED"

How would i go about searching for an array inside an array

$array1 = array('a,b,c,d,e,f,g,h,i,j,k');
$array1 = array(d,e,f,g,h');

I have tried


foreach($array1 as $haystack) {
if(preg_match($array2, $haystack) { // do something } }

foreach($array1 as $haystack) {
if(ereg($array2, $haystack) { // do something } }

foreach($array1 as $haystack) {
if(in_array($array2, $haystack) { // do something } }

But they dont work

Can anyone help, I have googled it but nothing seems to come up for an array inside an array

I only see single-value arrays (or, more precisely: normal variables). What exactly are you trying to achieve?

Sorry it should be

$array1 = array('a,b,c,d,e,f,g,h,i,j,k');
$array2 = array('d,e,f,g,h');

I want to see if ‘d,e,f,g,h’ is in ‘a,b,c,d,e,f,g,h,i,j,k’, if I use the following

[code][code]
foreach($array1 as $haystack) {
if(preg_match($array2, $haystack) { echo “Result $array2 is in $haystack”; } } // Outputs ‘d,e,f,g,h’ is in Array

foreach($array1 as $haystack) {
if(ereg($array2, $haystack) { echo “Result $array2 is in $haystack”; } } // Outputs ‘d,e,f,g,h’ is in Array

foreach($array1 as $haystack) {
if(in_array($array2, $haystack) { echo “Result $array2 is in $haystack”; } } // Outputs ‘d,e,f,g,h’ is in Array
[/code][/code]

The question I’m posing is, how is this:

$array1 = array('a,b,c,d,e,f,g,h,i,j,k'); $array2 = array('d,e,f,g,h');

different from this:

$array1 = 'a,b,c,d,e,f,g,h,i,j,k'; $array2 = 'd,e,f,g,h';

Apart from the first two being arrays, the values don’t change. And substr() will help you find a string in another string ;)

Sponsor our Newsletter | Privacy Policy | Terms of Service