| | |
Storing and Retrieving Number String/Array
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
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
The idea is:
PHP Syntax (Toggle Plain Text)
$a = 1; $b = 2; $c = 3; $alpha = $a + " " + $b + " " + $c; 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
to use them as string put quotations around them.
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
PHP Syntax (Toggle Plain Text)
$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.
php Syntax (Toggle Plain Text)
<?php $a = 1; $b = 2; $c = 3; $alpha = $a." ".$b." ".$c; echo $alpha; //prints 1 2 3 echo "<br />"; list($a1,$b1,$c1) = explode (" ",$alpha); echo $a1; //prints 1 echo $b1; //prints 2 echo $c1; //prints 3 ?>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
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
and if the number of values is unknown, you could also assign them directly to an array like so
PHP Syntax (Toggle Plain Text)
$alpha = "11 22 33 44 55 66"; $array = explode(" ", $alpha); /* Then you will have $array[0] = "11"; $array[1] = "22"; $array[2] = "33"; $array[3] = "44"; $array[4] = "55"; $array[5] = "66"; */ //and you can loop through them like this foreach($array as $value) { echo $value . "<br />"; }
Last edited by R0bb0b; Jun 18th, 2008 at 1:55 am.
Ok it worked but it didnt.
My small example did but when I changed it to my requirements I got this error:
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
My small example did but when I changed it to my requirements I got this error:
PHP Syntax (Toggle Plain Text)
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
![]() |
Other Threads in the PHP Forum
- Previous Thread: inserting into selected fields
- Next Thread: PHP/MySQL errors:-mysql_num_rows(): and mysql_fetch_array():
| Thread Tools | Search this Thread |
apache api array beginner binary body broken cakephp checkbox class cms code computing cron curl database date date/time delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert ip javascript joomla limit link list login mail memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex remote script search seo server sessions sms snippet source space sql static syntax system table thesishelp tutorial update upload url validator variable video web webdesign wordpress xml youtube







