vecho Posted October 29, 2007 Share Posted October 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75207-checking-sophisticated-arrays-with-isset/ Share on other sites More sharing options...
vecho Posted October 30, 2007 Author Share Posted October 30, 2007 perhaps it's not necessary to mention, that this kind of code - isset($main_table[$test[$x]][$layer[$j]]) doesn't do the job either... what i am trying to say, is that i am making the same mistake and don't what is it??? any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/75207-checking-sophisticated-arrays-with-isset/#findComment-380941 Share on other sites More sharing options...
aschk Posted October 30, 2007 Share Posted October 30, 2007 Can you give us some sample arrays for $test and $main_table and the starting value for $x. You probably find once you've intepreted the arrays the value you are looking for is in fact not set. Hence the loop termination. If $x is 0; What is $test[0] ? If $test[0] = "myvalue"; Then what does $main_table["myvalue"] equal? Quote Link to comment https://forums.phpfreaks.com/topic/75207-checking-sophisticated-arrays-with-isset/#findComment-381029 Share on other sites More sharing options...
vecho Posted October 30, 2007 Author Share Posted October 30, 2007 thanks for reply, here's how arrays are being created: $sql = "SELECT POSITION,ID,NAME,PARENT_ID from MYTABLE order by position"; ... while(list($POSITION,$ID,$NAME,$PARENT_ID)=oci_fetch_array($result_1)) { $layer[$POSITION]=$ID; $test[$POSITION]=$PARENT_ID; $id_table[$ID]=$NAME; $main_table[$PARENT_ID][$ID]=$NAME; $parent_table[$PARENT_ID]=$id_table[$ID]; }; then i call myfunc(..., $x=0, $main_table, $test, $layer, id_table, parent_table....) ... the reason i am doing this is because i need to sort $id_table, $main_table and $parent_table arrays $layer and $test arrays are doing sorting thing - so when i write $main_table[$test[$x]] this looks for a value that is under certain position (unfortunately position and id columns in database do not match at all, that's way i have to go through this mess) hope this makes the situation straight ! p.s. is this expression - $main_table[$test[$x]] - understood by php at all? if no, why? should i search for a workaround using nested foreach cycle? Quote Link to comment https://forums.phpfreaks.com/topic/75207-checking-sophisticated-arrays-with-isset/#findComment-381043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.