0

I've an array like that :

array(2) {
  ["dashboard"]=>
  array(3) {
    ["controller"]=>
    string(5) "Index"
    ["action"]=>
    string(5) "index"
    ["path"]=>
    string(34) "dashboard/user/example/{page}/{id}"
  }
  ["home"]=>
  array(3) {
    ["controller"]=>
    string(5) "Index"
    ["action"]=>
    string(6) "second"
    ["path"]=>
    string(10) "home/index"
  }
}

How get all "path" values in an array ? I tried to use array_search and several functions in PHP but this doesn't work.

3 Answers3

1
foreach($arr as $key=>$val){
    $path[] = $val['path']; //store all paths into an array
    //$path[$key] = $val['path']; //you can use this also to keep whose path is this
}
var_dump($path);
Bhaskar Jain
  • 1,651
  • 1
  • 12
  • 20
0

Simply use a foreach loop :

$paths = array();

foreach($array as $page) {
    $paths[] = $page['path'];
}

print_r($paths);
Elbarto
  • 1,213
  • 1
  • 14
  • 18
0

@Adrien PAYEN simply use array_column() like below by which you can get all values for a particular column of an array:

<?php
    print_r(array_column($yourArray, "path"));
lazyCoder
  • 2,544
  • 3
  • 22
  • 41