cliftonbazaar Posted May 30, 2009 Share Posted May 30, 2009 My program is using several arrays (have over a thousand variables so arrays are a must). At the moment I am simply exploding the arrays when needed and then imploding them if they need to be saved. This morning I was thinking that maybe I should put each array into its own $_SESSION at the start of the program so I don't have to keep imploding and exploding them, except imploding them in order to save any changes. Is there much difference in these two methods in the way it effects the server? Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/ Share on other sites More sharing options...
.josh Posted May 30, 2009 Share Posted May 30, 2009 I have to wonder why you need to have thousands of variables in memory in the first place, and if the more appropriate solution would be to rethink your system to not have so much data on-hand at once... Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845457 Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 Why can't you store those values in the database? Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845460 Share on other sites More sharing options...
cliftonbazaar Posted May 30, 2009 Author Share Posted May 30, 2009 Didn't explain that properly then - all the variables (including arrays) are in a database, I implode and explode arrays that are in the database. Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845480 Share on other sites More sharing options...
Philip Posted May 30, 2009 Share Posted May 30, 2009 But like CV said, is it really needed to have all of those variables, or could you just select what you needed (maybe a few at a time)? Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845482 Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 I have a question, what would exploding an array do? Wouldn't it just give you back the same array? ??? Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845498 Share on other sites More sharing options...
Philip Posted May 30, 2009 Share Posted May 30, 2009 Well, if you save a string in the DB like: "one, two, three" - explode that would get you an array ( 0 => "one", 1 => "two", 2 => "three") then implode that into something like "one - two - three" don't ask why I'd do something like that, but it's possible somebody would want to. Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845504 Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 I think you misread my question. What would exploding and array do? <?php $e = array('one', 'two', 'three'); $k = explode('???', $e); var_dump($k); ??? Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845507 Share on other sites More sharing options...
.josh Posted May 30, 2009 Share Posted May 30, 2009 I'm sure he meant exploding a string into an array and imploding back into a string. But I'm sure you knew that, and you're just being an ass. Stop it. That's my job. Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845509 Share on other sites More sharing options...
Philip Posted May 30, 2009 Share Posted May 30, 2009 Well, if you save a string in the DB like: "one, two, three" - explode that would get you an array... "one, two, three" would be from one value in the db. Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845510 Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 Crayon Violent - I actually wanted to know what exploding an array would do. In my tests, they just come back as the original array. I would think PHP would give me an error, but it doesn't. ??? Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845513 Share on other sites More sharing options...
.josh Posted May 30, 2009 Share Posted May 30, 2009 Crayon Violent - I actually wanted to know what exploding an array would do. In my tests, they just come back as the original array. I would think PHP would give me an error, but it doesn't. ??? er.. well when you try to explode an array, for instance: $x = range('a','z'); $y = explode(' ',$x); explode evaluates it as a string of value "Array" and explodes the string based on the delimiter. Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845516 Share on other sites More sharing options...
Philip Posted May 30, 2009 Share Posted May 30, 2009 You will get a notice warning: Notice: Array to string conversion in /path/test.php on line # Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845518 Share on other sites More sharing options...
.josh Posted May 30, 2009 Share Posted May 30, 2009 ah i don't have notices turned on. I got Array ( [0] => Array ) from ^^ Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845521 Share on other sites More sharing options...
cliftonbazaar Posted May 30, 2009 Author Share Posted May 30, 2009 Exploding an array allows you to put a value from a database into an array of values. For example if the database value is {Human, fighter, strong} then it could be exploded to abilities[0] = human abilities[1] = fighter abilities[2] = strong this helps in putting variables together in values that are needed on the one page and not having to have a thousand differant fields in a database. For me this system works fine, I'm just worried about putting strain on the server. Note that this is just a simple example, the reality is that the values are a lot bigger. Quote Link to comment https://forums.phpfreaks.com/topic/160229-arrays-and-when-they-should-be-used/#findComment-845534 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.