Skip to content
Advertisement

Getting a single attribute from a php array

I have a php array that I’ve filtered based on the datasetID the $result is therefore a single record.

I would like to echo a single attribute i.e. ["genus"] I’ve tried echo $result[0]['genus']; but that wont work. Any tips? I hope this is a simple one?

echo var_dump($result);

array(1) { [8]=> array(174) { ["type"]=> string(4) "None" ["modified"]=> string(0) "" ["language"]=> string(2) "en" ["license"]=> string(4) "None" ["rightsHolder"]=> string(4) "None" ["accessRights"]=> string(4) "None" ["bibliographicCitation"]=> string(4) "None" ["references"]=> string(4) "None" ["institutionID"]=> string(4) "None" ["collectionID"]=> string(4) "None" ["datasetID"]=> string(13) "5ff496c5254e3" ["institutionCode"]=> string(4) "None" ["collectionCode"]=> string(4) "None" ["datasetName"]=> string(4) "None" ["ownerInstitutionCode"]=> string(3) "GIA" ["basisOfRecord"]=> string(4) "None" ["informationWithheld"]=> string(4) "None" ["dataGeneralizations"]=> string(4) "None" ["dynamicProperties"]=> string(4) "None" ["occurrenceID"]=> string(4) "None" ["catalogNumber"]=> string(4) "None" ["recordNumber"]=> string(4) "None" ["recordedBy"]=> string(4) "None" ["individualCount"]=> string(4) "None" ["organismQuantity"]=> string(4) "None" ["organismQuantityType"]=> string(4) "None" ["sex"]=> string(4) "None" ["lifeStage"]=> string(4) "None" ["reproductiveCondition"]=> string(4) "None" ["behavior"]=> string(4) "None" ["establishmentMeans"]=> string(4) "None" ["degreeOfEstablishment"]=> string(4) "None" ["pathway"]=> string(4) "None" ["occurrenceStatus"]=> string(4) "None" ["preparations"]=> string(4) "None" ["disposition"]=> string(4) "None" ["associatedMedia"]=> string(4) "None" ["associatedReferences"]=> string(4) "None" ["associatedSequences"]=> string(4) "None" ["associatedTaxa"]=> string(4) "None" ["occurrenceRemarks"]=> string(4) "None" ["organismID"]=> string(4) "None" ["organismName"]=> string(4) "None" ["organismScope"]=> string(4) "None" ["associatedOccurrences"]=> string(4) "None" ["associatedOrganisms"]=> string(4) "None" ["previousIdentifications"]=> string(4) "None" ["organismRemarks"]=> string(4) "None" ["materialSampleID"]=> string(4) "None" ["eventID"]=> string(4) "None" ["parentEventID"]=> string(4) "None" ["fieldNumber"]=> string(4) "None" ["eventDate"]=> string(4) "None" ["eventTime"]=> string(4) "None" ["startDayOfYear"]=> string(4) "None" ["endDayOfYear"]=> string(4) "None" ["year"]=> string(4) "None" ["month"]=> string(4) "None" ["day"]=> string(4) "None" ["verbatimEventDate"]=> string(4) "None" ["habitat"]=> string(4) "None" ["samplingProtocol"]=> string(4) "None" ["sampleSizeValue"]=> string(4) "None" ["sampleSizeUnit"]=> string(4) "None" ["samplingEffort"]=> string(4) "None" ["fieldNotes"]=> string(4) "None" ["eventRemarks"]=> string(4) "None" ["locationID"]=> string(4) "None" ["higherGeographyID"]=> string(4) "None" ["higherGeography"]=> string(4) "None" ["continent"]=> string(4) "None" ["waterBody"]=> string(4) "None" ["islandGroup"]=> string(4) "None" ["island"]=> string(4) "None" ["country"]=> string(4) "None" ["countryCode"]=> string(4) "None" ["stateProvince"]=> string(4) "None" ["county"]=> string(4) "None" ["municipality"]=> string(4) "None" ["locality"]=> string(4) "None" ["verbatimLocality"]=> string(4) "None" ["minimumElevationInMeters"]=> string(4) "None" ["maximumElevationInMeters"]=> string(4) "None" ["verbatimElevation"]=> string(4) "None" ["minimumDepthInMeters"]=> string(4) "None" ["maximumDepthInMeters"]=> string(4) "None" ["verbatimDepth"]=> string(4) "None" ["minimumDistanceAboveSurfaceInMeters"]=> string(4) "None" ["maximumDistanceAboveSurfaceInMeters"]=> string(4) "None" ["locationAccordingTo"]=> string(4) "None" ["locationRemarks"]=> string(4) "None" ["decimalLatitude"]=> string(4) "None" ["decimalLongitude"]=> string(4) "None" ["geodeticDatum"]=> string(4) "None" ["coordinateUncertaintyInMeters"]=> string(4) "None" ["coordinatePrecision"]=> string(4) "None" ["pointRadiusSpatialFit"]=> string(4) "None" ["verbatimCoordinates"]=> string(4) "None" ["verbatimLatitude"]=> string(4) "None" ["verbatimLongitude"]=> string(4) "None" ["verbatimCoordinateSystem"]=> string(4) "None" ["verbatimSRS"]=> string(4) "None" ["footprintWKT"]=> string(4) "None" ["footprintSRS"]=> string(4) "None" ["footprintSpatialFit"]=> string(4) "None" ["georeferencedBy"]=> string(4) "None" ["georeferencedDate"]=> string(4) "None" ["georeferenceProtocol"]=> string(4) "None" ["georeferenceSources"]=> string(4) "None" ["georeferenceVerificationStatus"]=> string(4) "None" ["georeferenceRemarks"]=> string(4) "None" ["geologicalContextID"]=> string(4) "None" ["earliestEonOrLowestEonothem"]=> string(4) "None" ["latestEonOrHighestEonothem"]=> string(4) "None" ["earliestEraOrLowestErathem"]=> string(4) "None" ["latestEraOrHighestErathem"]=> string(4) "None" ["earliestPeriodOrLowestSystem"]=> string(4) "None" ["latestPeriodOrHighestSystem"]=> string(4) "None" ["earliestEpochOrLowestSeries"]=> string(4) "None" ["latestEpochOrHighestSeries"]=> string(4) "None" ["earliestAgeOrLowestStage"]=> string(4) "None" ["latestAgeOrHighestStage"]=> string(4) "None" ["lowestBiostratigraphicZone"]=> string(4) "None" ["highestBiostratigraphicZone"]=> string(4) "None" ["lithostratigraphicTerms"]=> string(4) "None" ["group"]=> string(4) "None" ["formation"]=> string(4) "None" ["member"]=> string(4) "None" ["bed"]=> string(4) "None" ["identificationID"]=> string(4) "None" ["identificationQualifier"]=> string(4) "None" ["typeStatus"]=> string(4) "None" ["identifiedBy"]=> string(4) "None" ["dateIdentified"]=> string(4) "None" ["identificationReferences"]=> string(4) "None" ["identificationVerificationStatus"]=> string(4) "None" ["identificationRemarks"]=> string(4) "None" ["taxonID"]=> string(4) "None" ["scientificNameID"]=> string(4) "None" ["acceptedNameUsageID"]=> string(4) "None" ["parentNameUsageID"]=> string(4) "None" ["originalNameUsageID"]=> string(4) "None" ["nameAccordingToID"]=> string(4) "None" ["namePublishedInID"]=> string(4) "None" ["taxonConceptID"]=> string(4) "None" ["scientificName"]=> string(4) "None" ["acceptedNameUsage"]=> string(4) "None" ["parentNameUsage"]=> string(4) "None" ["originalNameUsage"]=> string(4) "None" ["nameAccordingTo"]=> string(4) "None" ["namePublishedIn"]=> string(4) "None" ["namePublishedInYear"]=> string(4) "None" ["higherClassification"]=> string(7) "Eukarya" ["kingdom"]=> string(8) "Animalia" ["phylum"]=> string(8) "Chordata" ["class"]=> string(8) "Mammalia" ["order"]=> string(12) "Artiodactyla" ["family"]=> string(7) "Bovidae" ["genus"]=> string(5) "Capra" ["subgenus"]=> string(4) "None" ["specificEpithet"]=> string(4) "None" ["infraspecificEpithet"]=> string(4) "None" ["taxonRank"]=> string(4) "None" ["verbatimTaxonRank"]=> string(4) "None" ["scientificNameAuthorship"]=> string(4) "None" ["vernacularName"]=> string(4) "goat" ["nomenclaturalCode"]=> string(4) "None" ["taxonomicStatus"]=> string(4) "None" ["nomenclaturalStatus"]=> string(4) "None" ["taxonRemarks"]=> string(4) "None" ["commonName"]=> string(4) "None" ["elementName"]=> string(8) "Mandible" ["commonElementName"]=> string(4) "None" ["fileName"]=> string(16) "goat_mandibula_1" } }

Advertisement

Answer

If you are filtering the datasetId by array_filter utility. Then you can do one thing

$result = array_values(array_filter(....));

This would return you a new array with index starting from 0. After that you can try

echo $result[0]['genus'];

Hope this would help.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement