Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I remove values from array

    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,N ULL,'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

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    PHP Code:
    $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]);
      }


  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Quote Originally Posted by poyzn View Post
    PHP Code:

    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()
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by abduraooft View Post
    The above part can be replaced by array_diff()
    you are likely to have meant array_intersect()


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •