Hi
Can anybody help for the following issue
I have upto 100 integer values in varialbe $i
I want to store these values in single array name called year..
something like that $year = array();
Can any one help for this
Regards
Tom
Hi
Can anybody help for the following issue
I have upto 100 integer values in varialbe $i
I want to store these values in single array name called year..
something like that $year = array();
Can any one help for this
Regards
Tom
Take a look at the explode() function. If that does not help then please post the variable and the data and I or someone will be able to help you out a little more.
To choose the lesser of two evils is still to choose evil. My personal site
Hi James
thanks for your message
Explode() is exploding in this issue
Please refer the my code
$i displays numbers - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15PHP Code:<?php
$start = 1 ;
$end = 15;
for($i=start; $i<=end; $i++)
{
$i
}
I want to store these numbers in an array called $numbers
Last edited by traq; 02-10-2013 at 07:22 AM. Reason: please format your code and use the forum's [PHP][/PHP] BBCode tags
what?
...your code seems incomplete. Are you intending to create the variable$iin this loop?
Using$iboth to control the loop and create your result will have unexpected consequences.
In addition, it seems to conflict with what you said in your original post:
Ifresults inPHP Code:print $i;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
...then you don't have "integers" - you have a string.
If you want to convert that string into an array, you can use the explode() function as james suggested:If you don't actually need that stringPHP Code:<?php
$i = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15";
$numbers = explode( ' ',$i );
# now you have an array containing the numbers 1 - 15$ifor anything else, I'd suggest using range() to create your array instead:If neither of these are what you're asking about, please clarify.PHP Code:<?php
$numbers = range( 1,15 );
# same result
letom (02-11-2013)
Hi There
Thanks for your message and valuable advices.
Your Question --
...your code seems incomplete. Are you intending to create the variable$iin this loop?
Using$iboth to control the loop and create your result will have unexpected consequences.
In addition, it seems to conflict with what you said in your original post:
--------------------------------------------------------------------------------------
Answer
If iam going to write the full coding , in common sense iam missing the valuable time of me and people like you readers. that why i shortened it into a small code, as the coded form is already understand for you.
Your Question --
Explode() is exploding in this issue
what?
--------------------------------------------------------------------------
Answer
Exploding (means) - To show to be false or unreliable. http://www.thefreedictionary.com/exploding
I refer it with my program output , which is incorrect while using explode() function.
Your Question -
If neither of these are what you're asking about, please clarify.
-------------------------------------------------------------------------
Answer
The issue is solved when the range function is used.. Thanks for your kind and valuable suggestions
See u again
While I understand your goal, it is always much more helpful to give a working example.
Yes, it is a good idea to remove irrelevant code from your samples.
However, in order to be useful, the code that you do show us needs to demonstrate not only the part that is the problem, but also the part that works.
In this case, removing portions of your code only added to the confusion by implying other (false) problems.
Alright. How is it being unreliable or incorrect? What was the result it gave you, vs. what you expected?
The statement "it doesn't work" will not lead to a solution on its own.
You're quite welcome, I'm glad you got it figured out.
If your question has been answered, please mark your thread "resolved":
- On your original post (post #1), click [edit], then click [go advanced].
- In the "thread prefix" box, select "Resolved".
- Click [save changes].
Thanks..
False refers wrong or incorrect.. I got incorrect output while using explode() fn.
It would be nice, if readers will focus & discuss about the meaning and idea of post, not each and every words of post
The reason we expect clear questions is because it makes it easier to help you. This is all for you, not for us. And although it may feel excessive, the details really are important. We can't guess what you are thinking, so your posts need to be clear enough for us to understand all of the important details. If we don't understand them, we can't help.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
My focus was on your issue. To illustrate, if explode() had given you this result:the solution would be very different than if you had gotten this result:Code:bool( false )As Daniel says, we need to know the specifics of your problems, otherwise we're just making wild guesses.Code:array(1) [0] => string(36) "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
Bookmarks