PDA

View Full Version : how to make this Array(need help)


megatrue
11-17-2008, 03:43 PM
hello, I'm a newbie. Anyone can help me?
I have a problem with array.

$a=array("Dog","www.mydomain.com","Horse");

How to find www.mydomain.com with Regular expression and remove it. then rebuild a new arry without "www.mydomain.com". i know how to make a Regular expression.

Dismounted
11-18-2008, 03:24 AM
No need to use "intensive" regex functions.
$a = array(
'Dog',
'www.mydomain.com',
'Horse'
);
$find = array_keys($a, 'www.mydomain.com');

foreach ($find AS $key)
{
unset($a[$key]);
}

megatrue
11-18-2008, 09:59 AM
thank you
but if my array is:
$a = array(
'Dog',
'www.mydomain.com',
'www.mydomain.com/index.php',
'www.myotherdomain.com/index.php',
'www.myotherdomain.com',
'...',
'...',
'Horse'
);

this function array_keys() is not fittingly.