Help with an array

Discussion in 'PHP' started by aquasonic, Apr 1, 2008.

  1. #1
    I have an array that I want to split and display.

    I have this so far:

    $table_data = "7.5;6.5;6.0;7.5;8.5;10.5";
    print_r (explode(";",$table_data));
    PHP:
    Which will output this:
    Array ( [0] => 7.5 [1] => 6.5 [2] => 6.0 [3] => 7.5 [4] => 8.5 [5] => 10.5 ) 
    Code (markup):
    But what I want to do is to be able to take the value of the first array and just display the contents - so in this case I want to be able to print the information in [0] to one place, the information from [1] to another and so on.

    How do I display each section of the array on it's own?


    Thanks in advance.
     
    aquasonic, Apr 1, 2008 IP
  2. e = mc²

    e = mc² Peon

    Messages:
    138
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can print the 1st element of $Array as echo $Array[0]; and so on.
    Is that what you need?
    Thanks,
    e = mc²
     
    e = mc², Apr 1, 2008 IP
  3. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #3
    Yeh - I tried this but then it comes out wrong.

    Where I wan't the first array it displays '7'
    The second array displays '.'
    the third array displays '5'
    The fourth array displays ';'


    I need to tell it that the seperator is a semi-colon... but how?

    Thanks
     
    aquasonic, Apr 1, 2008 IP
  4. e = mc²

    e = mc² Peon

    Messages:
    138
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This should work fine according to this.
    Thanks,
    e = mc²
     
    e = mc², Apr 1, 2008 IP
  5. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #5
    Ah - I've worked it out now!

    Thanks, you pointed me in the right direction...

    It's as follows:

    $table_data = "7.5;6.5;6.0;7.5;8.5;10.5";
    
    $table_data_exploded = (explode(";",$table_data));
    PHP:
    and then

    echo $table_data_exploded[0];
    echo $table_data_exploded[1];
    echo $table_data_exploded[2];
    etc
    PHP:

    Brilliant :):D
     
    aquasonic, Apr 1, 2008 IP
  6. e = mc²

    e = mc² Peon

    Messages:
    138
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You're Welcome :D
    Thanks,
    e = mc²
     
    e = mc², Apr 1, 2008 IP