checking sophisticated - nested arrays with isset()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vecho
Forum Newbie
Posts: 3
Joined: Tue Oct 30, 2007 4:05 am

checking sophisticated - nested arrays with isset()

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The contents of the do..while block are always run before the while() expression is evaluated.
vecho
Forum Newbie
Posts: 3
Joined: Tue Oct 30, 2007 4:05 am

Post by vecho »

thanks for reply!
Last edited by vecho on Wed Nov 07, 2007 2:08 am, edited 1 time in total.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Code: Select all

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