amsgwp Posted July 14, 2013 Share Posted July 14, 2013 This code should be pretty self explanatory, but I'm struggling bad to get it to work. I want to check if the "propview" element is blank, if so, replace it with "No Contingencies". Simple right? $details_array = array( "propview" => JText::_('COM_IPROPERTY_PROPVIEW' ), "beds" => JText::_('COM_IPROPERTY_BEDS' ), "baths" => JText::_('COM_IPROPERTY_BATHS' ), "sqft" => (!$this->settings->measurement_units) ? JText::_('COM_IPROPERTY_SQFT' ) : JText::_('COM_IPROPERTY_SQM' ), "lotsize" => JText::_('COM_IPROPERTY_LOT_SIZE' ), "lot_acres" => JText::_('COM_IPROPERTY_LOT_ACRES' ), "yearbuilt" => JText::_('COM_IPROPERTY_YEAR_BUILT' ), "heat" => JText::_('COM_IPROPERTY_HEAT' ), "garage_type" => JText::_('COM_IPROPERTY_GARAGE_TYPE' ), "roof" => JText::_('COM_IPROPERTY_ROOF' )); if(empty($details_array["propview"])) { $details_array = array( "propview" => "No Contingencies" ); } It either doesn't do anything or it wipes out the entire array. Maybe the logic should be embedded in the original array, but I haven't found any examples that show that ever being done. Quote Link to comment https://forums.phpfreaks.com/topic/280149-replace-one-value-of-array-if-empty/ Share on other sites More sharing options...
Barand Posted July 14, 2013 Share Posted July 14, 2013 Just replace the single array element if(empty($details_array["propview"])) { $details_array["propview"] = "No Contingencies"; } Quote Link to comment https://forums.phpfreaks.com/topic/280149-replace-one-value-of-array-if-empty/#findComment-1440699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.