n33dl3 Posted March 11, 2007 Share Posted March 11, 2007 Hi, I have an array with the following entry: $rec['REC_DATE']: array=0: undefined=NULL If the REC_DATE entry is NULL I would like to set REC_DATE with today's date, and if REC_DATE is not NULL then nothing should happen. What would be the best way to achieve this, I have tried it with : if (!array_key_exists('REC_DATE', $res)) { $res['REC_DATE']=$today; } but that is not working. Thnx Regards Link to comment https://forums.phpfreaks.com/topic/42236-filter-undefined-null-array-setting/ Share on other sites More sharing options...
paul2463 Posted March 11, 2007 Share Posted March 11, 2007 where are you setting $today? $today = date("d-m-Y", strtotime("Now")); //if you dont have it anywhere here it is and where is $res coming from? if (!array_key_exists('REC_DATE', $res)) Link to comment https://forums.phpfreaks.com/topic/42236-filter-undefined-null-array-setting/#findComment-204962 Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 simply $today = date('Y-m-d'); will suffice as date() defaults to current date/time. Link to comment https://forums.phpfreaks.com/topic/42236-filter-undefined-null-array-setting/#findComment-204969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.