Thursday, 30 August 2018

PHP Retrieves all multidimensional associative array values

How can i get all values from multidimensional associative array I dont want to use print_r want to control my array put all the value in normal array with unique values my array is look like this

array (size=10)
  0 =>
    array (size=3)
      0 =>
        array (size=1)
          'Campaign' => string 'DEMO' (length=4)
      1 =>
        array (size=1)
          'Campaign' => string 'Home_Sec' (length=8)
      2 =>
        array (size=1)
          'Campaign' => string '' (length=0)
  1 =>
    array (size=0)
      empty
  2 =>
    array (size=0)
      empty
  3 =>
    array (size=1)
      0 =>
        array (size=1)
          'Campaign' => string 'Back_Brace' (length=10)
  4 =>
    array (size=2)
      0 =>
        array (size=1)
          'Campaign' => string 'Home_Sec' (length=8)
      1 =>
        array (size=1)
          'Campaign' => string '' (length=0)
  5 =>
    array (size=1)
      0 =>
        array (size=1)
          'Campaign' => string 'home_Sec_2' (length=10)
  6 =>
    array (size=1)
      0 =>
        array (size=1)
          'Campaign' => string 'Burial_Ins' (length=10)
  7 =>
    array (size=0)
      empty
  8 =>
    array (size=0)
      empty
  9 =>
    array (size=0)
      empty

I dont want to use print_r want to control my array put all the value in normal array with unique values

You can use array_walk
$array = array(...); //your values here
function output($item, $key) {
     echo $key . ' =>' . $item;
}
array_walk($array, 'output');

0 comments:

Post a Comment