1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Split Number down via PHP

Discussion in 'PHP' started by Fiverscripts, Oct 30, 2016.

  1. #1
    Hi All,
    SEMrush
    Im trying to split a number down e.g

    Number passed in: 1234567

    This would split down too:

    Number 1: 1
    Number 2: 2
    and so on..

    Whats the best way to do this?

    thanks,
     
    Fiverscripts, Oct 30, 2016 IP
    SEMrush
  2. Einheijar

    Einheijar Well-Known Member

    Messages:
    537
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    115
    #2
    
    $array = str_split("0123456789bcdfghjkmnpqrstvwxyz");
    
    PHP:
    Will give you an array with each individual char as an element
     
    Einheijar, Oct 30, 2016 IP
    Fiverscripts and sarahk like this.
  3. jestep

    jestep Prominent Member Premium Member

    Messages:
    3,661
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    You can also access a variable as an array without performing any manipulation at all.

    
    $number = 1234567;
    
    /*
    $number[0] //1
    $number[1] //2
    $number[2] //3
    $number[3] //4
    */
    
    Code (markup):
     
    jestep, Nov 1, 2016 IP
    Fiverscripts likes this.
  4. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,838
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #4
    Hi Both,

    thanks for your help this has been useful and i have now achieved what i was trying to do

    Matt
     
    Fiverscripts, Nov 1, 2016 IP