php - Empty or null array value not filter or remove from array list
Get the solution ↓↓↓I I have tried to remove null or empty values from array listing but not working.
Following is my array output..
{-code-1}
I have tried to remove empty array value using array_filter() but still empty value is showing when i print my array.
I also tried like,
$filtered = array_filter($myArray, function($var){return !is_null($var);} );
echo "<pre>List Data";print_r($filtered);
I want to remove1
index array from list
Answer
Solution:
An array whose values are empty strings is not the same asNULL
. You need to test the values.
You can callarray_filter()
on the element. This will return all the non-empty values in the array; if all the values are empty it will return an empty array, which will be condidered falsey by the outerarray_filter()
.
$filtered = array_filter($myArray, function($var){return array_filter($var);} );
Or you could just check whether a specific element such aspost_id
is empty:
$filtered = array_filter($myArray, function($var){return !empty($var['post_id']);} );
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the payload is invalid.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.