1

How do I get the if statement below, to return TRUE and therefore return my string "Africa is in this array"? Note: template is set to parse on INPUT (I cant use output for this template)

 <?php 
    $entryregion="{categories show_group='4' backspace='2'}{category_name}, {/categories}";
    $entryregionArr=(explode(',',$entryregion));
    print_r($entryregionArr);
    echo "<br />" ;
    if (in_array('Africa', $entryregionArr)) {
        echo "Africa is in this array";

    }
    ?>

the above print_r($entryregionArr); prints an array that looks like this. Array ( [0] => Africa [1] => South Africa [1] => Durban [1] => ) I think I want it to look more like this Array ( [0] => Africa [1] => South Africa [2] => Durban ) where Durban is in the 2nd key and the last key id deleted, but I am not sure why or how to do this. I have tried parse='inward' in the category tag. I had a recent suggestion through this site to use the explode() function and I am grateful because it has shown me that this is where my error is. Well, one step at a time. Any suggestions would be appreciated.

1 Answer 1

1

It's my personal advice not to mix up the EE tags with PHP code. There may cause issue because of "PHP Parsing Stage" sometime.

In your case, you can use PHP code like:

EDITED:

$this->EE =& get_instance();
    $res = $this->EE->db->select('cat_name')->where('group_id', 4)->get('categories')->result_array();
    foreach ($res as $r)
    {
        $entryregionArr[] = $r['cat_name'];
    }

    if (in_array('Africa', $entryregionArr)) {
        echo "Africa is in this array";
    }

I hope, it would help you.

6
  • Thanks for reading, you have the right idea! This looks great at a glance, but for some reason it doesn't work (the $ee() breaks the page). Its within an entry tag and php needs to be parsing on input. I like the idea of not mixing ee with php tags, because you bang-on, I have had a lot of issues with parsing stages. I had a little progress with this function in_array_r I found at this link link, but still not returning true. Ahhh! any more ideas, I would love to try, I am at my end on this one? Commented Jul 24, 2013 at 18:02
  • I edited the code. Please try and share your further findings... Commented Jul 24, 2013 at 18:11
  • Thanks, no luck. Still renders my page as code instead of parsing it. I am not sure I understand the complexity of the 1st line. Does it refer the entries within the entries tag? Commented Jul 24, 2013 at 18:22
  • Check if template preference have "Allow PHP?" as "Yes". Commented Jul 24, 2013 at 18:39
  • Yep, and allmost all the other php I have used on the page. You may understand the comment that I just placed under Robson Sobral's suggestion. Some of the php functionality works, other functionality does not. I would love to take the ee/categories out of the equation like you suggest to avoid parsing being an issue. I made mistake in my original question - php parsing is on INPUT not Output. Commented Jul 24, 2013 at 19:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.