1

I have to create string like $zn = "43,49,57,3,68,69"; from following array without using loop :

Array
(
    [0] => Array
        (
            ['pk_id'] => 43
        ),

    [1] => Array
        (
            ['pk_id'] => 49
        ),

    [2] => Array
        (
            ['pk_id'] => 57
        ),

    [3] => Array
        (
            ['pk_id'] => 3
        ),

    [4] => Array
        (
            ['pk_id'] => 68
        ),

    [5] => Array
        (
            ['pk_id'] => 69
        )

);

What are the ways I can do?

It should take less time and memory.

ashawley
  • 4,195
  • 1
  • 27
  • 40
Poonam
  • 104
  • 8

2 Answers2

3

use array_column with implode function in php

implode(',',array_column($a, 'pk_id'));
Amit Gaud
  • 756
  • 6
  • 15
3

You can use array_walk_recursive function:

$result = array();
array_walk_recursive($arr, function($v) use (&$result) {
    $result[] = $v;
});
echo implode('&', $result);

Read more about array_walk_recursive.