开发者

PHP show if with different categories array or variable?

Having some problems here, I think I am just overlooking something really simple...

I have a CMS that have multiple categories.

How do I create a variable or array that has the included categories groups that I want to use in my SHOW IF STATEMENT ??

So for example:

<?php  

        $catsrow = array(
    'cat_1' => '41','46','62', 
    'cat_2' => '41','45','63',
    'cat_3' => '41',开发者_如何转开发'43','65'

);

?>




<?php if 

    (catsrow[0] || catsrow[1] || catsrow[2]) == ($row_DetailRS1['category']) 

{ echo 'do work' } 

    else {  ?>

Thanks in advance!!

I guess what I am asking is, how do I compare an array with multiple groups inside. I need to compare different grouped categories..

Like $catsArray = ARRAY(cat_1 => '2,3,4' , cat_2 => '5,6,7' , cat_3 => '8,9,10')

if $row['cat_from_page'] == $catsArray (any of the groups) then SHOW THIS { }

????


you may need to explode the parts of the array

Kinda like $parts = explode(',' , $cat);

http://php.net/manual/en/function.explode.php

but you will need to implode the whole thing into one array

Like implode (',', $parts);

http://php.net/manual/en/function.implode.php


My Best guess at what you're trying to do:

$categories = array(
        'cat_1' => array(
            '41','46','62'
        ), 
        'cat_2' => array(
            '41','45','63'
        ),
        'cat_3' => array(
            '41','43','65'
        )
);

$row_DetailRS1['category'] = '41';

foreach($categories as $category => $items) {
    foreach($items as $item) {
        if($row_DetailRS1['category'] == $item) {
            echo "Item: ".$item." found in Category: ".$category."\n";
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜