Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Question about Implode

    I have a query for Selected Messages that looks like this...
    Code:
        array
          52 => string '1' (length=1)
          51 => string '1' (length=1)
          49 => string '1' (length=1)
          39 => string '1' (length=1)
          38 => string '1' (length=1)
          10 => string '1' (length=1)
          8 => string '1' (length=1)
          6 => string '1' (length=1)
          5 => string '1' (length=1)
          2 => string '1' (length=1)
          1 => string '1' (length=1)

    Is there a way to use implode but to reference the Array key instead of the value?


    What I want is to keep my current Array's structure, but get a results set like this...

    Code:
    $messagesToUpdate = 52, 51, 49, 39, 38, 10, 8, 6, 5, 2, 1

    But to get this code to work...
    Code:
    	$messagesToUpdate = implode(', ', $_POST['msgArray']);
    ...I had to modify my Array structure like this...
    Code:
        array
          52 => string '52' (length=2)
          51 => string '51' (length=2)
          49 => string '49' (length=2)
          39 => string '39' (length=2)
          38 => string '38' (length=2)
          10 => string '10' (length=2)
          8 => string '8' (length=1)
          6 => string '6' (length=1)
          5 => string '5' (length=1)
          2 => string '2' (length=1)
          1 => string '1' (length=1)

    Hope that makes sense?!

    Sincerely,


    Debbie

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    100
    Thanks
    16
    Thanked 11 Times in 11 Posts
    Use array_keys() - http://ca3.php.net/manual/en/function.array-keys.php

    Code:
    $messagesToUpdate = implode(', ', array_keys($_POST['msgArray']));
    The CodingForums Funny Images thread ** Now with 20+ pages!! ** - http://www.codingforums.com/geek-news-humour/245405-funny-images.html

  • Users who have thanked >ssp-cdr< for this post:

    doubledee (01-04-2013)

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by >ssp-cdr< View Post
    Use array_keys() - http://ca3.php.net/manual/en/function.array-keys.php

    Code:
    $messagesToUpdate = implode(', ', array_keys($_POST['msgArray']));
    Exactly what I needed.

    Thanks!


    Debbie


  •  

    Posting Permissions

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