display different results based on array value

Napify App Source

I am trying to display a custom HTML page if the user that requests the page has the [is_vip] value equal to "5".

this is the line I'm trying to run:

 <?php if ($membership["is_vip"] == 5) { ?>
do stuff
    <?php } else { 
do other stuff

However it's not displaying the custom results properly, the contents of $membership look like this when printed.

    Array
(
    [0] => napify\Model\Membership Object
        (
            [is_vip] => 5
        )

)

This should be simple but i've been stuck in this for hours.

php

Answers

answered 4 months ago AbraCadaver #1

That's an integer indexed array with one element containing an object. Plus the code you posted won't parse and is a parse error. Once you fix the syntax:

<?php if ($membership[0]->is_vip == 5) { ?>
 do stuff
<?php } else { ?>
 do other stuff
<?php } ?>

Make sure to use error reporting when developing:

error_reporting(E_ALL);
ini_set('display_errors', '1');

answered 4 months ago user2852143 #2

I believe AbraCadaver is correct with their post

<?php if ($membership[0]->is_vip == 5) { ?>

but there is also an issue with your closing tag.

<?php } else {

should be

<?php } else { ?>

and your else statement needs to be closed with a

<?php } ?>

comments powered by Disqus