Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/75207-checking-sophisticated-arrays-with-isset/
Share on other sites

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!

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?

 

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.