2

我有一个问题,如果“lastpost”设置为“No Posts”,我需要忽略任何数组键

这是 $sublast 的数组转储:

    array(3) { [0]=> array(9) { ["forum_category_id"]=> string(1) "3" ["name"]=>  string(15) "Sub category #1" ["description"]=> string(39) "This is a short description test.... #2" ["topics"]=> string(1) "0" ["lastpost"]=> string(8) "No Posts" ["lastpostauthor"]=> string(1) " " ["lastposturl"]=> string(88) "http://test.codetrove.com/index.php?route=forum/read&forum_path=3&forum_post_id=" ["posts"]=> int(0) ["href"]=> string(81) "http://test.codetrove.com/index.php?route=forum/forum_category&forum_path=1_3" } [1]=> array(9) { ["forum_category_id"]=> string(1) "7" ["name"]=> string(16) "Test sub Sub cat" ["description"]=> string(0) "" ["topics"]=> string(1) "2" ["lastpost"]=> string(26) "Mon Apr 1, 2013 1:00:42 pm" ["lastpostauthor"]=> string(16) "Justine Smithies" ["lastposturl"]=> string(90) "http://test.codetrove.com/index.php?route=forum/read&forum_path=7&forum_post_id=63" ["posts"]=> int(2) ["href"]=> string(81) "http://test.codetrove.com/index.php?route=forum/forum_category&forum_path=1_7" } [2]=> array(9) { ["forum_category_id"]=> string(1) "9" ["name"]=> string(11) "Test cat #3" ["description"]=> string(20) "Short description #3" ["topics"]=> string(1) "2" ["lastpost"]=> string(26) "Mon Apr 1, 2013 1:00:15 pm" ["lastpostauthor"]=> string(16) "Justine Smithies" ["lastposturl"]=> string(90) "http://test.codetrove.com/index.php?route=forum/read&forum_path=9&forum_post_id=62" ["posts"]=> int(2) ["href"]=> string(81) "http://test.codetrove.com/index.php?route=forum/forum_category&forum_path=1_9" } } 

这是我正在尝试做的代码,只是它搞砸了,因为它总是针对正确的顶部条目,但是如果将“lastpost”设置为“No Posts”,我需要一种方法来删除顶部条目,所以它得到正确的信息。

                        <?php
                        $sublast = $forum_category['children'];
                        foreach ($sublast as $key => $row) {
                        $dates[$key]  = $row['lastpost']; 
                        }
                        array_multisort($dates, SORT_ASC, $sublast);
                        $lastitem = $sublast[count($sublast) - 1];
                         var_dump($sublast); 
                        ?>

这是 $lastitem 的转储:

    array(9) { ["forum_category_id"]=> string(1) "3" ["name"]=> string(15) "Sub category #1" ["description"]=> string(39) "This is a short description test.... #2" ["topics"]=> string(1) "0" ["lastpost"]=> string(8) "No Posts" ["lastpostauthor"]=> string(1) " " ["lastposturl"]=> string(88) "http://test.codetrove.com/index.php?route=forum/read&forum_path=3&forum_post_id=" ["posts"]=> int(0) ["href"]=> string(81) "http://test.codetrove.com/index.php?route=forum/forum_category&forum_path=1_3" }

正如你所看到的,当整个数组条目应该被删除时它需要“无帖子”,所以它需要 array[1] 这是我需要的。

请问有什么想法吗?

4

2 回答 2

1

在php中使用unset函数删除元素

于 2013-04-01T12:31:03.143 回答
0

Unset 将满足您的需求。

unset($array)
于 2013-04-01T12:33:37.183 回答