Reputation: 61
I am trying for a while now to remove values for certain length from an array, an I can't seem to get it done. I have removed white spaces and emtpy arrays using the built in functions, but I also want to remove items from the array that have less than 30 characters.
My code is:
$data = array();
$cells = $dom->getElementsByTagName('td');
foreach($cells as $node) {
foreach($node->childNodes as $child) {
$data[] = array($child->nodeName => $child->nodeValue);
$data = array_map('array_filter', $data);
$data = array_filter($data);
}
}
Upvotes: 1
Views: 140
Reputation: 3093
I would change your function to something like this:
foreach($cells as $node){
foreach($node->childNodes as $child) {
// check the length is greater than or equal to 30
if(strlen($child->nodeValue) >= 30 ){
$data[ $child->nodeName ] = $child->nodeValue;
$data[ $child->nodeName ] = array_map('array_filter', $aTempData);
$data[ $child->nodeName ] = array_filter($aTempData);
}
}
}
If you wanted to remove from starting array you can use unset()
as with your original method
Upvotes: 1