Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to implode multi-dimensional array keys using PHP v5.5

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 239
    Comment on it

    Hello Readers, If you want to implode the array keys from multi-dimensional array then now PHP 5.5 offers you much easier way to do this.

    Lets see the example as below:-

    Array
    (
        [0] => Array
            (
                [studenID] => 54874
                [City] => New Delhi
                [Marks] => 256
                [School] => 2
            )
    
        [1] => Array
            (
                [studenID] => 54875
                [City] => Mumbai
                [Marks] => 159
                [School] => 6
            )
    )
    

    Now suppose you want the result as New Delhi, Mumbai

    Now by using PHP V5.5 you just have to write this code syntax:-

    echo implode(', ', array_column($array, 'City'));
    

    Where $array is the name of array and City is my key.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: