I'm having some problems grasping how to match a one-dimensional array with a two-dimensional array. So I have one array, a one-dimensional, that contains numbers (e.g. 1, 2, 3, 4, 5...) and one two-dimensional array that contains numbers and some text (e.g. [1][dog], [2][cat], [3][mouse]...)
So now what I want to do is to use the first array, to see if that matches the second arrays numbers, e.g. if array[0] (contains value '1') matches array2[x] then output the array2's text, array2[x][text].
Any help is appriciated!
EDIT:
As per request I've exported the arrays, I don't know if that'll help, but here we go:
arrayX ( 0 => '1',
1 => '2'
)
arrayY ( 0 => array ( 0 => 'cat' ),
1 => array ( 0 => 'dog' )
)
I suppose this'd work similar to a tag system? If arrayX contains an entry with the value '1', then compare this with arrayY and output the number-match.
Do you mean that the second array is like the following: $array[0]['cat'] = 'dog'
Or $array[0] = 'cat'
If it's the latter, you can just iterate over the first array, outputting values from the second array like so
foreach ($array1 as $key) {
echo $array2[$key];
}
$arr1 = array( 1, 2, 3, 5, 7, 11, 13, 17 );
$arr2 = array(
2 => array( 'text' => 'Foo', 'animal' => 'dog' ),
3 => array( 'text' => 'Bar', 'animal' => 'cat' ),
5 => array( 'text' => 'bla', 'animal' => 'rabbit' ),
11 => array( 'text' => 'blub', 'animal' => 'horse' ),
13 => array( 'text' => 'foobar', 'animal' => 'mouse' ) );
for ( $i = 0; $i < count( $arr1 ); $i++ )
{
if ( isset( $arr2[$i] ) )
{
echo $arr2[$i]['text'] . "<br />
";
}
}
Something like this?