bluefrog Posted December 20, 2015 Share Posted December 20, 2015 Hi, I have a group of numbers like this: 1 - 2 - 3 - 4 I want to break that single variable apart and enter the number only into an array, then print out each number as needed (as entered into the array). Trouble is I have literally no idea where to even begin, and little knowledge of php, probably less than basic. I am assuming I will need something like preg or explode? Any brief examples would be very much appreciated, also, if I wanted to list these from lowest to highest is that much or a task? Many thanks in advance Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 20, 2015 Share Posted December 20, 2015 Have you read the manual for the 'explode' function? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 20, 2015 Share Posted December 20, 2015 Yes, explode() will put the numbers into an array. sort() will put the array in ascending values. Use a foreach() loop to echo the elements in the array. Quote Link to comment Share on other sites More sharing options...
bluefrog Posted December 21, 2015 Author Share Posted December 21, 2015 Thank you Barand, exactly the info I was looking for. @jinerjm, yes I have but was more than a little confused by some of the examples - remember I don't code php, I am very very new. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 21, 2015 Share Posted December 21, 2015 Then - keep on reading. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 21, 2015 Share Posted December 21, 2015 @bluefrog: When researching a function you have never used before, here are some suggestions for a beginner: 1) Read through the entire manual page (at least everything before the user contributed notes). If something doesn't make sense to you at first, continue till the end of the content for that function. Then re-read to see if those sections now make sense to you. 2. Pay special attention to the examples. Find one that is close to what you want to accomplish and do it exactly as it is shown. 3. Take the example and make small modifications to change it to what you need. After each modification, run it and ensure the change is working as you expect. If there is a problem, review your code to see what the problem was and fix it. If you can't figure it out at that point, then post what you have to this forum and explain what you are trying to achieve, what you have done so far, and what the problems are that you are facing. Quote Link to comment Share on other sites More sharing options...
bluefrog Posted December 21, 2015 Author Share Posted December 21, 2015 @ginerjim lol, I intend to, I find php a most versatile language, however I guess by the time I've learned it something will have replaced it lol. I was really looking to see if I had selected the correct function (?). @psycho thanks. Because I'm still wet behind the ears so to speak, I was having trouble deciding between the two, they both seemed to do the same job which is why I posted, a clarification really. But sound advice, thanks Quote Link to comment 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.