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

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? – JayB Jul 24 '13 at 18:02
  • I edited the code. Please try and share your further findings... – Bhashkar Yadav Jul 24 '13 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? – JayB Jul 24 '13 at 18:22
  • Check if template preference have "Allow PHP?" as "Yes". – Bhashkar Yadav Jul 24 '13 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. – JayB Jul 24 '13 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.