Jump to content

Archived

This topic is now archived and is closed to further replies.

drkstr

*SOLVED*making associative array keys read only, or sanity checking it's values?

Recommended Posts

Is there an easy way to make the keys of an associative array read-only, and preferably the data type of the value? I am passing an associative array of object vars to a client side Flash script where someone else will be writing the code to update it and pass it back. I want to make sure I can safely reassign the updated data back to the object, is there an elegant way to do this, or should I just loop through and compare the new array with the original and exit on error if anything changed?

thanks!
...drkstr

Share this post


Link to post
Share on other sites
I don't think there is a way to make the keys read-only.  At least I've never come across it.

Share this post


Link to post
Share on other sites
Thanks for the sponce ober! I guess I'll just loop through and compare the data types of the array passed in through the parameter against those of the original. Hopefully I don't pick up/lose any keys.

thanks again!
...drkstr

Share this post


Link to post
Share on other sites
You could put a check in the code
[code]
<?php
$array = array ('x' => 1, 'y' => 2, 'z' => 3);

$orig_keys = array_keys($array);

    //
    // processing here
    //

$modified_array = array ('x' => 4, 'y' => 5, 'w' => 6);

$keys = array_keys($modified_array);

if ($keys == $orig_keys) {
    echo 'OK';
}
else {
    echo "Keys changed";
}

?> [/code]

Share this post


Link to post
Share on other sites
That's a handy little trick. I didn't know you could compare arrays directly with the '==' operator.

I think I now have enough info to make sure nothing jiggy happens to my array in the Flash code.

Thanks everyone for the help!
...drkstr

Share this post


Link to post
Share on other sites

×

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.