-4

Adding a string with a variable $a = 'ABC-01-222222'; with $b = 1; and it should give $a = 'ABC-01-222223'

GeekMania
  • 15
  • 1
  • 9
  • 1
    Explode this string into 3 variables and process each individually. Then concatenate to display. – Phantom Jul 08 '14 at 14:05
  • Show your code. What have you tried so far? – oliakaoil Jul 08 '14 at 14:06
  • Are you going to show us what you tried? – Bill Criswell Jul 08 '14 at 14:06
  • I know i did used String conversion to numbers http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion using the above link ...but i did failed in getting answer. so i didn't posted the code. I need a short methodology(i mean an small snippet method) that's it...i don't anybody to correct my code @oliakaoil – GeekMania Jul 08 '14 at 14:10
  • Do please remove the negative points in there ... i don't need you to correct my code – GeekMania Jul 08 '14 at 14:12
  • This site is for programming questions. it is not a "do my job for me", especially when you can't even be bothered to try doing this yourself, or show what you've tried. And note that I said "questions". You haven't asked one. You're basically just stating a demand, and expecting us to do it for you. – Marc B Jul 08 '14 at 14:13
  • hey @MarcB am not asking for answers i clearly mentioned in my comments that i have the intention in methods only. I don't need your answer for the example i provided – GeekMania Jul 08 '14 at 14:16

1 Answers1

2

You can use explode() to split the value of $a into three parts. Then add $b to the third item of the array, and then re-join the parts using implode():

$a = 'ABC-01-222222';
$b = 1;

$parts = explode('-', $a);
$parts[2] += $b;

$a = implode('-', $parts);
echo $a;
Gergo Erdosi
  • 36,694
  • 21
  • 106
  • 90
  • It's impossible to know if this is actually what he needs, or whether or not your answer just happens to work for the specific example. You also shouldn't encourage these kinds of questions by answering them blindly. – oliakaoil Jul 08 '14 at 14:10
  • Hey @oliakaoil if you don't want to answer, you just carry on your work don't interfere with others initiative – GeekMania Jul 08 '14 at 14:14
  • Hey @GeekManiax There's a reason this site allows downvoting and commenting without answers. We are both trying to make the site better by giving our opinion. Telling me "don't say anything if you don't have something nice to say" is *seriously* missing the point. – oliakaoil Jul 08 '14 at 14:18
  • @oliakaoil OP will decide if this is what he needs. If not, I will ask him to improve his question and based on the new information I will either edit or delete my answer. – Gergo Erdosi Jul 08 '14 at 14:18
  • @GergoErdosi what I'm saying is you should have done that *first* before giving some canned answer that doesn't actually help the OP. – oliakaoil Jul 08 '14 at 14:19
  • @GergoErdosi Ya this is what i need, Thanks for helping me – GeekMania Jul 08 '14 at 14:19
  • @oliakaoil see i didn't posting a unmeaningful question or something. Also this is not only for Correcting Coding Stuffs and helping someone who is really struggling with coding. This site is for way of improvising the development methods. Its upto you mark a downvote, if you feel it's wrong. But don't make a mess in a initiative. It doesn't improve a new comer – GeekMania Jul 08 '14 at 14:26
  • Also @oliakaoil see this question. http://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string?rq=1 why this question is posted and its answered. They may see in the php documentation itself. but why they are posting is they need many answers to choose from & then they understand easy. So is it makes sense for you!!!! – GeekMania Jul 08 '14 at 14:30