Sunnyisles Posted January 4, 2022 Share Posted January 4, 2022 (edited) Hi, can someone please help me to simplify this? Thanks $time=$json_nba->league->standard[$nextgame]->startTimeEastern; $string = $game; <?php echo $string[6]; echo $string[7];?>/<?php echo $string[4]; echo $string[5];?> <?php echo $string[9]; echo $string[10]; echo $string[11];?>-<?php echo $string[12]; echo $string[13]; echo $string[14];?> Edited January 4, 2022 by Sunnyisles Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/ Share on other sites More sharing options...
Solution Barand Posted January 4, 2022 Solution Share Posted January 4, 2022 echo "$game[6] $game[7]/$game[4] $game[5] $game[9] $game[10] $game[11] - $game[12] $game[13] $game[14]"; 41 minutes ago, Sunnyisles said: $string = $game; is redundant Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/#findComment-1593161 Share on other sites More sharing options...
Sunnyisles Posted January 4, 2022 Author Share Posted January 4, 2022 Yo are right, thanks! $json_nba=llamar_api("http://data.nba.com/data/10s/prod/v1/2021/teams/1610612748/schedule.json"); $nextgame=$json_nba->league->lastStandardGamePlayedIndex+1; $game=$json_nba->league->standard[$nextgame]->gameUrlCode; $time=$json_nba->league->standard[$nextgame]->startTimeEastern; <?php echo "$game[6]$game[7]/$game[4]$game[5] $game[9]$game[10]$game[11] - $game[12]$game[13]$game[14]";?> Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/#findComment-1593162 Share on other sites More sharing options...
NotionCommotion Posted January 5, 2022 Share Posted January 5, 2022 Don't know whether more efficient or not from a processing perspective but using printf/sprintf will be more efficient from a your time perspective. Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/#findComment-1593176 Share on other sites More sharing options...
ginerjm Posted January 5, 2022 Share Posted January 5, 2022 I find it funny when I see people using sprintf/printf to display something that a simple echo accomplishes. I NEVER use those 2 functions. Don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/#findComment-1593177 Share on other sites More sharing options...
NotionCommotion Posted January 5, 2022 Share Posted January 5, 2022 9 hours ago, ginerjm said: I find it funny when I see people using sprintf/printf to display something that a simple echo accomplishes. I NEVER use those 2 functions. Don't understand. I never used to and also didn't originally understand the point of doing so, but eventually came to appreciate how sprintf/printf offers some separation of concerns. I am sure it is personal choice but other reasons why I like to use them include: Ability to format/pad/etc. Consistency when working with associated arrays and multiple-dimension sequential arrays. Ability to apply a function to the arguments, ability for arguments to be a method applied to an object, etc. Reuse of templates. Less troubleshooting values that need to be escaped. Easier to read and less dinking around with presentation (once you get used to them!). Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/#findComment-1593186 Share on other sites More sharing options...
gizmola Posted January 5, 2022 Share Posted January 5, 2022 I personally don't use printf/sprintf much either, but you make some good points. I also coded in c, before php was a thing, and those are wrappers around the standard c library afaik. They were there for c programmers coming to php to get up and running fast, but that's probably not a very substantial group anymore. I agree they do have some nice utility in many circumstances, especially where number formatting is important. If you are going to want/need localization, I doubt they are something you would still want to use though. Quote Link to comment https://forums.phpfreaks.com/topic/314385-explode/#findComment-1593197 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.