Skip to main content
Tim M's user avatar
Tim M's user avatar
Tim M's user avatar
Tim M
  • Member for 6 years, 8 months
  • Last seen more than 2 years ago
awarded
comment
PHP assign values within in_array
Here's what I've decided to use: <?php $days = [ 1 => 'M', 2 => 'T', 3 => 'W', 4 => 'TH', 5 => 'F', 6 => 'S', 7 => 'Su', 8 => 'Online', ]; $classDays = [1,3]; if(count($classDays)=='0') { $classDays = [8]; } $result = array_map(function ($a) use($days) { return $days[$a]; }, $classDays); echo implode(', ', $result);
comment
PHP assign values within in_array
@KIKOSoftware The result could contain any number of days and the output will be in numerical order. I've added the checkbox HTML to my post. Thanks.
revised
PHP assign values within in_array
added 2096 characters in body
Loading…
comment
PHP assign values within in_array
@KIKOSoftware No worries. In the posted example, I expect the output to be M W F. If the user doesn't select any options when selecting the checkboxes on the input form, they will be assigned the Online value.
revised
PHP assign values within in_array
added 130 characters in body
Loading…
comment
PHP assign values within in_array
@SᴀᴍOnᴇᴌᴀ - You've summed it up :) Primarily, my code seems repetitive so I would think it would be better to loop, but I'm not sure of the best way to go about that.
comment
PHP assign values within in_array
@KIKOSoftware - 3v4l.org/Sghnh#v7.4.30 is the link I posted and there isn't an error. The link you posted is missing the values for $classDays.
asked
Loading…
awarded
accepted
comment
Getting data from an API in JSON format
Thank you so much! Your post has lots of great information that I've spent the past couple days working on. I've learned a lot, so thank you! :)
awarded
comment
Getting data from an API in JSON format
Thanks for the link Sam, I read it over. I also updated my code, so hopefully I can get some feedback on my changes. Thank you.
awarded
revised
Getting data from an API in JSON format
I replaced the code section with my new updated and improved code. Suggestions appreciated!
Loading…
asked
Loading…