Storing and Retrieving Number String/Array

Reply

Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Storing and Retrieving Number String/Array

 
0
  #1
Jun 18th, 2008
I have a few number values that I need to store in one string/array and then use it at a later time.

The idea is:

  1. $a = 1;
  2. $b = 2;
  3. $c = 3;
  4.  
  5. $alpha = $a + " " + $b + " " + $c;
  6.  
  7. echo $alpha;

The output of alpha in turn would be "6" I want it to be "1 2 3".

Also after it is stored possible to break it up again and then retrieve the values of "1 2 3" and store them back to new variables of $a1, $b1, $c1.

Thankyou, Regards X
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Storing and Retrieving Number String/Array

 
0
  #2
Jun 18th, 2008
to use them as string put quotations around them.

  1. $a = '1';

then to break them up again use explode() function

if you are just trying to store some data just seperate the values using commas by i think using implode(do use it much) and use explode(",",$str); to get them out again.
Last edited by kkeith29; Jun 18th, 2008 at 12:50 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Storing and Retrieving Number String/Array

 
1
  #3
Jun 18th, 2008
  1. <?php
  2. $a = 1;
  3. $b = 2;
  4. $c = 3;
  5. $alpha = $a." ".$b." ".$c;
  6. echo $alpha;
  7. //prints 1 2 3
  8. echo "<br />";
  9. list($a1,$b1,$c1) = explode (" ",$alpha);
  10. echo $a1; //prints 1
  11. echo $b1; //prints 2
  12. echo $c1; //prints 3
  13. ?>
. is the concatenation operator not + !
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #4
Jun 18th, 2008
Nav to the rescue once again my hero!

Umm another thing will that work if the variables are double digits example 11, 22, 33 just the same for singular digits? Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Storing and Retrieving Number String/Array

 
1
  #5
Jun 18th, 2008
as long as they are spaced by the " " character, yes.

and if the number of values is unknown, you could also assign them directly to an array like so
  1. $alpha = "11 22 33 44 55 66";
  2. $array = explode(" ", $alpha);
  3.  
  4. /*
  5. Then you will have
  6. $array[0] = "11";
  7. $array[1] = "22";
  8. $array[2] = "33";
  9. $array[3] = "44";
  10. $array[4] = "55";
  11. $array[5] = "66";
  12. */
  13.  
  14. //and you can loop through them like this
  15. foreach($array as $value)
  16. {
  17. echo $value . "<br />";
  18. }
Last edited by R0bb0b; Jun 18th, 2008 at 1:55 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Storing and Retrieving Number String/Array

 
0
  #6
Jun 18th, 2008
wow, i feel like an idiot. how did i miss the + thing. guess i am use to javascript.

actually, after i read my post again, i have no idea what i was thinking. ignore my post.
Last edited by kkeith29; Jun 18th, 2008 at 2:04 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #7
Jun 18th, 2008
You think you are.

Who do you think first used the +.

Haha ya just been working with other coding conventions and forgot that in php it was . instead of +.

Thanks guys working it out now and keep you all informed
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #8
Jun 18th, 2008
Ok it worked but it didnt.

My small example did but when I changed it to my requirements I got this error:

  1. Allowed memory size of 134217728 bytes exhausted (tried to allocate 10 bytes)

Any idea on how I can fix this?
or will I need to program the above in java to work?
If so will it even work in java if it dosent work in php?

Thanks, Regards X
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Storing and Retrieving Number String/Array

 
0
  #9
Jun 18th, 2008
what exactly are you doing to cause that error? just exploding variables and such.??
Last edited by kkeith29; Jun 18th, 2008 at 3:48 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #10
Jun 18th, 2008
Using alot of numbers? (which I think I declare too many/alot as an array?)
Last edited by OmniX; Jun 18th, 2008 at 8:27 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC