0

I have the following data as an array, the dataset is actually much larger but this is just a sample...

Array
(
    [0] => Array
        (
            [id] => 107
            [displayname] => Test 11
            [frontpage] => 0
        )

    [1] => Array
        (
            [id] => 201
            [displayname] => Test 2
            [frontpage] => 1
        )

    [2] => Array
        (
            [id] => 47
            [displayname] => Test 82
            [frontpage] => 0


   )
)

I am trying to output a new array with just the 'displayname' value, seems really simple but I am struggling to find an example.

Ray Toal
  • 86,166
  • 18
  • 182
  • 232
fightstarr20
  • 11,682
  • 40
  • 154
  • 278

1 Answers1

2

you can try something like this:

$sourceArray = array( /* THIS IS THE ARRAY WITH YOUR DATA */ );
$displaynames = array(); /* THIS IS THE NEW ARRAY, FOR THE DISPLAYNAMES */
foreach ($sourceArray as $arrayItem) {
    $displaynames[] = $arrayItem['displayname'];
}

it will iterate over the source-array $sourceArray and puts only the displayname for each item into a the new (empty) array $displaynames.

Jan
  • 2,853
  • 2
  • 21
  • 26