I have a question concerning multidimensional arrays. I'm trying to write code that will search through the MD array and print out a result when it finds a match. To search through the array i'm using nested for loops. My code looks like this:
for ($v = 0; $v < count ($mdarray); $v++)
{ for ($x = 0; $x <= 2; $x++)
{ print "$mdarray[$v][$x]";}}
This will run through the array fine, but I need it to search for a certain value, and then output data once it finds it. I've tried inserting a if condition, but I haven't been able to make it output the desired results. I've only been able to make it output the print statement multiple times, or nothing at all. Here is an example of my code with the if condition inside the for loop:
for ($v = 0; $v < count ($mdarray); $v++)
{for ($x = 0; $x <= 2; $x++)
{if ($mdarray[$v][$x] == 'bleh') {print 'You have a bleh!';}}}
There will be many options for it to check for, so more than 1 if will probably be needed. (Still in the process of learning how to do that!) That is, it will have to check for much more things than just 'bleh'. It may need to check for 'blah' or 'bah' and so on, and return the correct output for that particular value.
Here is an example of how my arrays are built (They contain jibberish just for testing purposes):
$array1 = array ('bleh', 'blah', 'bah');
$array2 = array ('yak', 'smak', 'meh');
$multiarray = array ('array1' => $array1, 'array2' => $array2);
I'm still in the process of learning php, so it may be an easy fix that will make me slap my self for not seeing it! Any help would be much appreciated! Thanks