www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] comma + array

  1. #1
    Join Date
    Feb 2006
    Location
    india
    Posts
    678

    resolved [RESOLVED] comma + array

    Hi all,

    I have some values in a array defined as number[] in a list box.

    foreach($_POST['number'] as $key=>$value)
    {
    $reg .=$value.",";
    }

    So if i select 1 2 3 then the above code is producing 1,2,3, but i want to have it as 1,2,3

    So number of commas is one less then number of elements present in a array and it will be always true.

    I am running the above foreach loop but everytime I am getting a comma at the last of the array values......Could you please suggest me how can i remove the last comma

    Thanks
    Raj

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    PHP Code:
    $tmpARRAY = array();
    foreach(
    $_POST['number'] as $value) {
      
    $tmpARRAY[] = $value;
    }
    $reg implode(","$tmpARRAY); 

  3. #3
    Join Date
    Feb 2006
    Location
    india
    Posts
    678
    Its simply great...feeling shame now.........

    Thanks mate,
    Raj

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    You're welcome!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles