Basically I have this array $code:
Array
(
[1] => Array
(
[0] => FRANCE
[1] => 26422
[2] => 61748
[3] => 698477678
)
[2] => Array
(
[0] => UNITED STATES
[1] => 545
[2] => 2648
[3] => 55697455
)
[3] => Array
(
[0] => CANADA
[1] => 502
[2] => 1636
[3] => 15100396
)
[4] => Array
(
[0] => GREECE
[1] => 0
[2] => 45
[3] => 458
)
I want to unset all the countries with $code[$key][1] == 0 so I tired this:
$code = array_filter($code, function (array $element) {
return !preg_match('(0)i', $element[1]);
});
But it returns all the countries unless the one that has in $code[$key][1] 0, Like this:
Array
(
[1] => Array
(
[0] => FRANCE
[1] => 26422
[2] => 61748
[3] => 698477678
)
[2] => Array
(
[0] => UNITED STATES
[1] => 545
[2] => 2648
[3] => 55697455
)
Any how I can achieve this? Thanks!
return $element[1] !== 0;? (orreturn $element[1] !== "0";in case of a string). In your sample data this will remove onlyGREECE. The regular expression would^0$but don't use regular expressions here.