...

View Full Version : How can I remove values from array



great_friend
12-13-2010, 02:05 PM
Hi Guys,

I have an event calendar which values are coming from array
I want to remove all values except those which dates are available in mysql database

below are the code
<?php
$days = array(
1=>array('/weblog/archive/2004/Jan/02','linked-day'),
2=>array('/weblog/archive/2004/Jan/03','linked-day'),
3=>array('/weblog/archive/2004/Jan/08','linked-day'),
4=>array('/weblog/archive/2004/Jan/22','linked-day'),
5=>array('/weblog/archive/2004/Jan/22','linked-day'),
6=>array('/weblog/archive/2004/Jan/22','linked-day'),
7=>array('/weblog/archive/2004/Jan/22','linked-day'),
8=>array('/weblog/archive/2004/Jan/22','linked-day'),
9=>array('/weblog/archive/2004/Jan/22','linked-day'),
10=>array('/weblog/archive/2004/Jan/22','linked-day'),
11=>array('/weblog/archive/2004/Jan/22','linked-day'),
12=>array('/weblog/archive/2004/Jan/22','linked-day'),
13=>array('/weblog/archive/2004/Jan/22','linked-day'),
14=>array('/weblog/archive/2004/Jan/22','linked-day'),
15=>array('/weblog/archive/2004/Jan/22','linked-day'),
16=>array('/weblog/archive/2004/Jan/22','linked-day'),
17=>array('/weblog/archive/2004/Jan/22','linked-day'),
18=>array('/weblog/archive/2004/Jan/22','linked-day'),
19=>array('/weblog/archive/2004/Jan/22','linked-day'),
20=>array('/weblog/archive/2004/Jan/22','linked-day'),
21=>array('/weblog/archive/2004/Jan/22','linked-day'),
22=>array('/weblog/archive/2004/Jan/22','linked-day'),
23=>array('/weblog/archive/2004/Jan/22','linked-day'),
24=>array('/weblog/archive/2004/Jan/22','linked-day'),
25=>array('/weblog/archive/2004/Jan/22','linked-day'),
26=>array('/weblog/archive/2004/Jan/22','linked-day'),
27=>array('/weblog/archive/2004/Jan/22','linked-day'),
28=>array('/weblog/archive/2004/Jan/22','linked-day'),
29=>array('/weblog/archive/2004/Jan/22','linked-day'),
30=>array('/weblog/archive/2004/Jan/22','linked-day'),
31=>array('/weblog/archive/2004/Jan/22','linked-day'),
);

?>

I want to remove all the above values except which dates are available in mysql table fields

here is mysql table and few sample data

es_events CREATE TABLE `es_events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dt` varchar(255) DEFAULT NULL,
`event` varchar(255) DEFAULT NULL,
`detail` text,
`active` enum('yes','no') DEFAULT NULL,
PRIMARY KEY (`id`)
)

insert into `es_events`(`id`,`dt`,`event`,`detail`,`active`) values (2,'22','yhh1','dd xcv&nbsp; <strong>Lorem Ipsum</strong> is simply dummy text of the printing and \r\ntypesetting industry. Lorem Ipsum has been the industry\'s standard dummy\r\n text ever since the 1500s, when an unknown printer took a galley of \r\ntype and scrambled it to make a type specimen book. It has survived not \r\nonly five centuries, but also the leap into electronic typesetting, \r\nremaining essentially unchanged. It was popularised in the 1960s with \r\nthe release of Letraset sheets containing Lorem Ipsum passages, and more\r\n recently with desktop publishing software like Aldus PageMaker \r\nincluding versions of Lorem Ipsum. <br>','yes'),(3,'2',NULL,NULL,'yes'),(4,'5',NULL,NULL,'yes'),(5,'10',NULL,NULL,'yes'),(6,'11',NULL,NULL, 'yes'),(7,'13',NULL,NULL,'yes'),(8,'14.',NULL,NULL,'yes');(6,'2010-12-11',NULL,NULL,'yes'),(7,'2010-12-13',NULL,NULL,'yes'),(8,'2010-12-14.',NULL,NULL,'yes');

please help me guys and let me know how can i resolved this problem

Thank you soo much

poyzn
12-13-2010, 03:58 PM
$mysql_dates = array(); // array of dates from the db - just select dates into array
$my_dates = array(); // you $days array
foreach($my_dates as $key => $val)
{
if(!in_array($key, $mysql_dates))
{
unset($my_dates[$key]);
}
}

abduraooft
12-13-2010, 04:01 PM
foreach($my_dates as $key => $val)
{
if(!in_array($key, $mysql_dates))
{
unset($my_dates[$key]);
}
}

The above part can be replaced by array_diff() (http://php.net/array_diff)

poyzn
12-13-2010, 06:46 PM
The above part can be replaced by array_diff() (http://php.net/array_diff)
you are likely to have meant array_intersect()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum