user982124 user982124 - 1 month ago 6
PHP Question

PHP - Check if element exists in this Array

I'm retrieving a database record which is stored in a variable $record. If I do a:

echo '<p><pre>'.print_r($record).'</pre></p>';


I get the following:

FileMaker_Record Object
(
[_impl] => FileMaker_Record_Implementation Object
(
[_fields] => Array
(
[Title] => Array
(
[0] => Alaska 24/7
)

[Status] => Array
(
[0] => Popular
)

[Author] => Array
(
[0] => Rick Smolan and David Elliot Cohen
)

[Publisher] => Array
(
[0] => DK Publishing
)

[Cover Photo Credit] => Array
(
[0] => Evan R. Steinhauser, Anchorage Daily News
)

[Description] => Array
(
[0] => The remarkable photographs showcased in Alaska 24/7 are the result of an epic project, America 24/7, which harnessed the talents of more than 25,000 photographers.
)

[Quantity in Stock] => Array
(
[0] => 50
)

[Number of Pages] => Array
(
[0] => 192
)

[Cover Image] => Array
(
[0] => /fmi/xml/cnt/AK-cover.jpg?-db=FMPHP_Sample&-lay=Form%20View&-recid=1&-field=Cover%20Image(1)
)

)

[V5e7ec2d5] => Array
(
)

[_recordId] => 1
[_modificationId] => 2
[_layout] => FileMaker_Layout Object
(
[_impl] => FileMaker_Layout_Implementation Object
(
[_fm] => FileMaker_Implementation Object
(
[V73ee434e] => Array
(
[charset] => UTF-8
[locale] => en
[logLevel] => 3
[hostspec] => 127.0.01
[recordClass] => FileMaker_Record
[prevalidate] =>
[database] => FMPHP_Sample
[username] => admin
[password] => testing123
)

[Vea4b3413] =>
[V9a3dcbce] =>
)

[_name] => Form View
[_fields] => Array
(
[Title] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Title
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => text
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Status] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Status
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => text
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Author] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Author
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => text
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Publisher] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Publisher
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => text
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Cover Photo Credit] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Cover Photo Credit
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => text
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Description] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Description
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => text
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Quantity in Stock] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Quantity in Stock
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => number
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Number of Pages] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Number of Pages
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => number
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

[Cover Image] => FileMaker_Field Object
(
[_impl] => FileMaker_Field_Implementation Object
(
[_layout] => FileMaker_Layout Object
*RECURSION*
[_name] => Cover Image
[_autoEntered] =>
[_global] =>
[_maxRepeat] => 1
[_validationMask] => 0
[_validationRules] => Array
(
)

[_result] => container
[_type] => normal
[_valueList] =>
[_styleType] =>
[_maxCharacters] => 0
)

)

)

[_relatedSets] => Array
(
)

[_valueLists] => Array
(
)

[Vab234ad8] => Array
(
)

[_database] => FMPHP_Sample
[_extended] =>
)

)

[_fm] => FileMaker_Implementation Object
(
[V73ee434e] => Array
(
[charset] => UTF-8
[locale] => en
[logLevel] => 3
[hostspec] => 127.0.0.1
[recordClass] => FileMaker_Record
[prevalidate] =>
[database] => FMPHP_Sample
[username] => admin
[password] => testing123
)

[Vea4b3413] =>
[V9a3dcbce] =>
)

[_relatedSets] => Array
(
)

[_parent] =>
)

)


I need to do some checking to see if the field I'm after exists in the list of fields returned with the $record object. For example I would like to see if the field 'Status' is contained within the [_fields] => Array list of fields (would be true in this example).

I'm assuming I can use something like this:

if (in_array('Status', _fields)) {


but not sure of the exact syntax here and haven't been able to get this to work so far.

Answer

Seems like you have an embedded object called FileMaker_Record_Implementation Object. Might be worth seeing if you have access to the source code of this Class as it may provide getters/setters for the attributes within.

Or you could try directly accessing the property like this:

if(!isset($record->_impl->_fields['Status'])){
    // Status doesn't exist
}
Comments