Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:50:14+00:00 2026-06-15T06:50:14+00:00

I am trying to Json decode something and get the value I want. But

  • 0

I am trying to Json decode something and get the value I want.
But I get PHP undefined index error.
This is my code.

<?php
$json = '[{"totalGamesPlayed":25,"championId":0}]';
$data = json_decode($json,true); 

$games = $data['totalGamesPlayed'];
echo $games;
?>

The problem is the “[” “]” are messing with my code…
I am using an API to get some values.
What I get is this : http://pastebin.com/XrqkAbJf
I need the totalGamesPlayed,the champion ID’s except zero (82,106 and 24)
and the TOTAL_SESSIONS_WON and TOTAL_SESSIONS_LOST for these ID’s…
For a start, let’s find out how can I bypass the “[” and “]” symbols,and then things may be easier..
Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:50:15+00:00Added an answer on June 15, 2026 at 6:50 am

    Access your code like this

    $games = $data[0]['totalGamesPlayed'];
    

    Code for getting other info

    <?php
    
    $json = 'PUT YOUR EXAMPLE JSON HERE';
    $data = json_decode($json,true); 
    
    $seasonWon = 0;
    $seasonPlayed = 0;
    foreach($data as $stats) {
        if($stats['championId'] != 0) {
            echo '<br><br>Total Games Played:'. $stats['totalGamesPlayed'];    
            echo '<br>champion Ids :'.$stats['championId'];
            foreach($stats['stats'] as $stat) {
                if($stat['statType'] == 'TOTAL_SESSIONS_WON') {
                    $seasonWon = $stat['value'];
                    echo '<br>TOTAL_SESSIONS_WON :'.$seasonWon;
                }
    
                if($stat['statType'] == 'TOTAL_SESSIONS_LOST')
                echo '<br>TOTAL_SESSIONS_LOST :'.$stat['value'];
    
                if($stat['statType'] == 'TOTAL_SESSIONS_PLAYED') {                
                    $seasonPlayed = $stat['value'];
                    echo '<br>TOTAL_SESSIONS_PLAYED :'.$seasonPlayed;                
                }
            }
            echo '<br>Games Ratio(TOTAL_SESSIONS_WON / TOTAL_SESSIONS_PLAYED): ('. $seasonWon.'/'.$seasonPlayed.'):'. ($seasonWon/$seasonPlayed);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to decode a json string returned from flickr within my PHP code.
I am trying to parse this json data from the url but i get
I am trying to decode the Google Dictionary API JSON response with PHP, but
I am trying to decode a JSON string into an array but i get
I'm trying to put together something to decode a Json string and not having
I came across this problem when trying to decode json into an array ,
I'm trying to decode a JSON with jQuery. Here's what I get (for instance
could anyone here help me with php an decoding json? Im trying to decode
I am trying to decode a JSON string using json_decode() in PHP. Part of
I'm trying to get some JSON data from a url like this: $url =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.