Page 1 of 1

checking sophisticated - nested arrays with isset()

Posted: Tue Oct 30, 2007 4:22 am
by vecho
hi all,

i have been trying to get my array checked for existing values with isset function:

function myfunc (..., $x, $main_table, $test,....)
{
do {$x++;} while (!isset($main_table[$test[$x]]));
}

$main_table, $test, - arrays that are being passed as function parameters
$x - is a number (start index) that's also being passed as function parameter

PROBLEM: {$x++;} is not being executed cause (!isset($main_table[$test[$x]])) is being skiped or so... :/

any ideas how to fix it or get it work?

p.s. i have tried - do {$x++;} while (!array_key_exists($test[$x],$main_table)); - and still no luck

Posted: Tue Oct 30, 2007 4:32 am
by CoderGoblin
Have you tried looking into the foreach structure. ? You can nest foreach's into several levels. You have the ability to use foreach ($array as $key=>$value), they are (normally) easily readable etc. All in all I prefer to use them whenever I handle arrays.

Posted: Tue Oct 30, 2007 10:36 am
by feyd
The contents of the do..while block are always run before the while() expression is evaluated.

Posted: Tue Oct 30, 2007 11:40 am
by vecho
thanks for reply!

Posted: Tue Oct 30, 2007 12:03 pm
by neophyte

Code: Select all

$array['key']=null;
isset($array['key']);
//returns false
array_key_exists might be a better option.