Jump to content

How can i remove empty element or element with no [a-zA-Z0-9] from a array?


colap

Recommended Posts

Array
(
    [0] => Array
        (
            [0] => ubuntu
            [1] => 
            [2] => apache
        )
}

I want to remove [0][1] element then the new array will be

Array
(
    [0] => Array
        (
            [0] => ubuntu           
            [1] => apache
        )
}

@CoolAsCarlito - How on earth do you figure that?

 

Use a foreach() loop, a conditional and unset().

 

foreach( $array as $k => $v ) {
$v = trim($v);
if( empty($v) ) {
	unset($array[$k]);
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.