lundi 2 décembre 2019

Remove items (and keys) from array with a value of 0 PHP

I am trying to remove items from my array to make a new array with only items in it that have a value greater than 0. I tried stuff with the foreach loop, looked it up on internet, but nothing worked.

Here is my array

$productarray = array(
  'a' => 6,
  'b' => 0,
  'c' => 2,
  'd' => 1,
  'e' => 3,
  'f' => 4,
);

expected output:

  'a' => 6,
  'c' => 2,
  'd' => 1,
  'e' => 3,
  'f' => 4,

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire