0
$array = array(
'name'      => 'john',
'age'       => '25',
'birthday'  => '02-03-1988',
'gender'    => 'male',
'telephone' => '98676878',
'location'  => 'Australia'
);

$array_slice = array_slice($array, 0, 3);

foreach($array_slice as $key => $val) {
  if($key !== 'age') {
  echo $key.' => '.$val.'<br>'; 
  }
}

Output:

name     => john
birthday => 02-03-1988

How to display 3 values of array?

So, I want output to be like this:

name     => john
birthday => 02-03-1988
gender   => male

I am very beginner in programmer, thanks for help.

Ajie Kurniyawan
  • 393
  • 2
  • 18

1 Answers1

0

Update: new solution after exchanging some comments below

You must filter the array and get the result in a new array. Then you display the content of the second array.

To filter your original array, use either array_intersect_key or array_filter functions.

Pascal Le Merrer
  • 5,883
  • 20
  • 35
  • I am sorry if my question is not clear, that's just an example.. my array is more long and random.. but I know some key and I don't want to display it.. I use array_slice to create pagination.. – Ajie Kurniyawan Mar 01 '14 at 19:24
  • I'm sorry too, because what you want to achieve is still not clear for me. Do you want to display all but some value, for which you know the key? – Pascal Le Merrer Mar 01 '14 at 19:50
  • Yes, my array is files, I want to display all files but not for some file.. assume my files are 20, and I create 2 page list using array_slice (because it is too long), Page1 = 10 files and Page2 = 10 files, but my problem is when I hide some file, assume 3 files are hidden.. my page displays 7 files on Page1 and 10 files on Page2.. What I want is 10 files on Page1 and 7 files on Page2... anyway thanks for your help... – Ajie Kurniyawan Mar 01 '14 at 20:11