Jump to content

Split numbers from '-' delimited list and enter them into an array


bluefrog

Recommended Posts

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 :)

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

@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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.