r/PHPhelp•
puttyguy

Associative array questions, finding instances of properties

Let's try this here, fucked up and posted this in r/php I didn't read that subs stance on "not a support area".

Anyways, I'm modifying some code for a client and not sure what to do here, I do mostly front-end stuff so this is a little out of my comfort zone.

What's the best way to find the last instance of a particular property in an array? Here's a sample one set, there are about 30 of these sets in this one array.

[31] => stdClass Object
    (
        [definition] => stdClass Object
            (
                [id] => 31
                [title] => Contacts
                [input_type] => separator
                [required] => 0
                [multiple] => 0
                [validation_regex] => 
                [select_options] => 
                [published] => 1
            )

        [value] => 
    )

I'm trying to check for last instance of the following:

[input_type] => separator

The separator type will never be the last item in the array, it always has items proceeding it.

Another question, as I loop through this array, what is the best way to check the next array set to see if it is a 'separator'.

The current method is fed this array of "custom_fields" and returns an html array by way of a foreach. It uses a case statement for each 'input_type', then adds that back in to the html array.

Let me know if you need some more information to correctly inform me of the best approach to solving my issues

Posted Jul 25, 2014, 4:07 PM UTC

58
Loading comments…