Jump to content

Explode


Sunnyisles
Go to solution Solved by Barand,

Recommended Posts

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 by Sunnyisles
Link to comment
Share on other sites

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]";?>

Link to comment
Share on other sites

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:

  1. Ability to format/pad/etc.
  2. Consistency when working with associated arrays and multiple-dimension sequential arrays.
  3. Ability to apply a function to the arguments, ability for arguments to be a method applied to an object, etc.
  4. Reuse of templates.
  5. Less troubleshooting values that need to be escaped.
  6. Easier to read and less dinking around with presentation (once you get used to them!).
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.